I am new to VB so bear with me... I've got a subroutine which opens a CSV spreadsheet on a website. I need to grab some data based on a Date. I type in the requested date on my spreadsheet and have the macro format it to the same format on the remote spreadsheet (dd.mmm.yy) and use the Cell.Find in order to find the row in which to start my copy of data from. Problem is i get error 91, Object variable or with Block Variable not set. I inserted code to properly handle the msg but it doesn't explain why it doesn't find the particular date in the spreadsheet which it does exist. Using the msgbox(getdate) immediately prior to the Cell.Find line I determined that the format was correct (10.Nov.07) which is in column A. I copied this remote spreadsheet to my harddrive and ran the code with no problems. I'm stumped.
Sub GET_ONTDEMAND()
On Error GoTo Errorhandler
Dim GetDate As Date
Dim rowVal As Integer
Dim FileDate As String
Dim formatdate As String
Dim myrange As Range
FileDate = Range("B2").Value
GetDate = Range("c2").Value
formatdate = Format([GetDate], "dd.mmm.yy")
'Workbooks.Open Filename:="c:\\zonaldemands.csv"
'Windows("ZonalDemands.csv").Activate
Workbooks.Open Filename:=" &
FileDate & ".csv"
Windows("ZonalDemands_" & FileDate & ".csv").Activate
Range("a2").Select
Set myrange = Cells.Find(What:=formatdate, LookIn:=xlValues,
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False)
If Not myrange Is Nothing Then myrange.Activate
rowVal = ActiveCell.Row
Range("A" & rowVal, "G" & rowVal + 167).Select
Selection.Copy
Windows("Shadow Pricing 2007.xls").Activate
Range("a5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("g5:g200").Copy
Range("d5").PasteSpecial
Range("e5:g200").ClearContents
Range("a1").Select
Workbooks(" & FileDate &
".csv").Close SaveChanges:=False
Exit Sub
Errorhandler:
MsgBox (Err.Number & ", " & Err.Description)
End Sub
Sub GET_ONTDEMAND()
On Error GoTo Errorhandler
Dim GetDate As Date
Dim rowVal As Integer
Dim FileDate As String
Dim formatdate As String
Dim myrange As Range
FileDate = Range("B2").Value
GetDate = Range("c2").Value
formatdate = Format([GetDate], "dd.mmm.yy")
'Workbooks.Open Filename:="c:\\zonaldemands.csv"
'Windows("ZonalDemands.csv").Activate
Workbooks.Open Filename:=" &
FileDate & ".csv"
Windows("ZonalDemands_" & FileDate & ".csv").Activate
Range("a2").Select
Set myrange = Cells.Find(What:=formatdate, LookIn:=xlValues,
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False)
If Not myrange Is Nothing Then myrange.Activate
rowVal = ActiveCell.Row
Range("A" & rowVal, "G" & rowVal + 167).Select
Selection.Copy
Windows("Shadow Pricing 2007.xls").Activate
Range("a5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("g5:g200").Copy
Range("d5").PasteSpecial
Range("e5:g200").ClearContents
Range("a1").Select
Workbooks(" & FileDate &
".csv").Close SaveChanges:=False
Exit Sub
Errorhandler:
MsgBox (Err.Number & ", " & Err.Description)
End Sub