A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Rick
I appreciate your patience with my problem. Here is what I made to show you the problem. I start a new blank wb. In A1 I place the header "FormulaDates". In C1, the header "RealDates". In A2 I enter the date 1-Mar-11. In A3 I enter the formula =A2+1. Using the fill handle I drag this formula down to A6. I now show dates from 1-Mar-11 to 5-Mar-11 in A2:A6. In C2 I enter 1-Mar-11. Using the fill handle (no formulas) I drag this date down to C6. C2:C6 now shows the same dates as A2:A6. I name the respective date ranges by their headers.
In B1 I enter 3-Mar-11 (the date I'm searching for.)
I write the following code:
Sub FindDate()
Dim SearchDate As Date, rSearchRng As Range, rFoundCell As Range
SearchDate = Range("B1")
'Set rSearchRng = Range("FormulaDates")
Set rSearchRng = Range("RealDates")
Set rFoundCell = rSearchRng.Find(What:=SearchDate)
MsgBox rFoundCell.Address(0, 0)
End Sub
Note that there are 2 lines that start with "Set SearchRng". You remark out one of them so that you are searching either "FormulaDates" or "RealDates". If you search "FormulaDates", the Msgbox line will error out with "Object variable or With block variable not set". If you search "RealDates" you get C4. My question is why is that error produced? I again thank you for your time. Your time is the most valuable thing you can give me. Otto