Compare Cells on Sheet to ListBox Selection

G

Guest

Hello.

Listbox2 contains selections from Listbox1. I want to be able to see if
the value of a cell on a sheet is contained within the values of Listbox2. I
can not figure out a code that will allow me to say something similar to "If
Range(ColumnD & r).Value NOT IN myList2Company Then..."

Thank you for your help in advance.

Here's my code:

Set LBox2 = ListBox2

myList2Company = LBox2.List

Dim DelCompRow(65000) As String

For r =2 to LastRow
'This is where my problem is: If Range(ColumnD & r).Value NOT IN
myList2Company Then
DeleteThisRow(r)="YES"
End If
Next r
 
T

Tom Ogilvy

Set LBox2 = ListBox2

myList2Company = LBox2.List

Dim DelThisRow(1 to 65000) As String
Dim bfound as Boolean
bFound = False
For r =2 to LastRow
for i = 0 to Ubound(myList2Company,1)
if Cells(r,4).value = MyList2company(i) then
bFound = True
exit for
end if
Next
if Not bFound then
DeleteThisRow(r)="YES"
End If
Next r
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top