Tuesday, 1 October 2013

VBA - Finding a date

VBA - Finding a date

I have 2 workbooks book1 & book2. Both book1 and book2 have first row as
dates
e.g. Book1
A B C
Jan-13 Feb-13 Mar-13
1 4
2 5
3 6

Book2
A B C
Jan-13 Feb-13 Mar-13
1 4 3
5 7 6
9 8 1

The idea is to select a date from Book 1 and find if the date exists in
book2 and copy the contents of book 2 column into book1 column
e.g. if I select Mar-13 in book 1, I should be able to find Mar-13 in book
2 and copy C3 to C5 from book2 to C3 to C5 of book1.
I am struggling with the find command in vba, I am using something like
this to find
With ThisWorkbook.ActiveSheet.Range("A1:Z1")
Set rngSMonthYr = .Find(What:=dtMonthYr, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext)
But it isnt working at all.
Any help would be very much appreciated.
Thanks, Aaron

No comments:

Post a Comment