Determining if a value exists in a column

MikeLiberty

Board Regular
Joined
Aug 13, 2010
Messages
55
Apologies if this has been addressed elsewhere, I couldn't find it.

I'm trying to determine if a value in a named range in one worksheet exists in column A of another worksheet. If it does, I want to set up a warning message, if not, I need to copy and paste some data. I had most of it working, but when I tried to limit the search to 1 column instead of the entire sheet, I broke something. Its been driving me crazy. Any help is appreciated. The relevant code is below.

Dim LastMonth As Boolean

LastMonth = Workbooks("MOR Workbook.xls").Worksheets("AWP12mo").Range("A:A").Find(What:=Worksheets("DataRetention").Range("RetentionDate").Value, _
After:= Range("A1"), LookIn:=xlFormulas, Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate


If LastMonth = True Then ..... {Rest of Code}
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try

Code:
Dim LastMonth As Range

Set LastMonth = Workbooks("MOR Workbook.xls").Worksheets("AWP12mo").Range("A:A").Find(What:=Worksheets("DataRetention").Range("RetentionDate").Value, _
After:=Range("A1"), LookIn:=xlValues, Lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)


If Not LastMonth Is Nothing Then
 
Upvote 0
Try

Code:
Dim LastMonth As Range
 
Set LastMonth = Workbooks("MOR Workbook.xls").Worksheets("AWP12mo").Range("A:A").Find(What:=Worksheets("DataRetention").Range("RetentionDate").Value, _
After:=Range("A1"), LookIn:=xlValues, Lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
 
 
If Not LastMonth Is Nothing Then

Thanks, that got me through the find. However, LastMonth is always registering as Nothing now, so it will always do the copy and paste. Any Idea why?
 
Upvote 0
I changed the Lookat and Lookin parameters. Perhaps you need to set them back to what you had.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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