User-defined type not defined

detriez

Board Regular
Joined
Sep 13, 2011
Messages
145
Office Version
  1. 365
Platform
  1. Windows
I've got a named range (nPersonalEmailDomain) with email domains... gmail.com, yahoo.com etc
I need to delete the entire row where an email in Column C is on the nPersonalEmailDomain list

So, If an email in Column C = bob@gmail.com, delete the entire row

This code fails with Compile Error: User-defined type not defined at Dim nRng As Range, rng As Range, c As Cell, n As Cell

VBA Code:
Sub PersonalEmails(Control As IRibbonControl)
Dim nRng As Range, rng As Range, c As Cell, n As Cell

Set nRng = Range("nPersonalEmailDomain") 'my named range containing the list of personal email domains
Set rng = Range("C2", ActiveSheet.Cells(Rows.Count, "c").End(xlUp)) 'get col C parameters

For Each c In rng 'Look at each item in col C
  For Each n In nRng
    If InStr(c.Text, n.Text) > 0 Then
      c.EntireRow.Delete 'Delete rows with match to named range
      Exit For
    End If
  Next
Next

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,282
Office Version
  1. 365
Platform
  1. Windows
There is no Cell type, change Cell to Range.
 

detriez

Board Regular
Joined
Sep 13, 2011
Messages
145
Office Version
  1. 365
Platform
  1. Windows
Thanks @Norie That resolved my issue (final code below if anyone can use it)

This may not be the most efficient way to do this as it hangs for about 8 minutes before it finally completes

I will start a new thread for help

VBA Code:
Sub PersonalEmails(Control As IRibbonControl)

Dim nRng As Range, rng As Range, c As Range, n As Range

Set nRng = Range("nPersonalEmailDomain") 'my named range containing the list of personal email domains
Set rng = Range("C2", ActiveSheet.Cells(Rows.Count, "c").End(xlUp)) 'get col C parameters

For Each c In rng 'Look at each item in col C
  For Each n In nRng
    If InStr(c.Text, n.Text) > 0 Then
      c.EntireRow.Delete 'Delete rows with match to named range
      Exit For
    End If
  Next
Next

End Sub
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,282
Office Version
  1. 365
Platform
  1. Windows
Instead of 2 loops you should have one loop for the range you are checking.

Within that loop you could use Application.Match to check if the value in column C is in the range 'nPersonalEmailDomain.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,722
Messages
5,637,988
Members
416,997
Latest member
Beni Gal

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top