User-defined type not defined

detriez

Board Regular
Joined
Sep 13, 2011
Messages
193
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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
There is no Cell type, change Cell to Range.
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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
Back
Top