Excel 2002 SP3
I'm trying to write a set of macros to read ; text files and do some charting.
So I have Workbooks.OpenText working to open the data properly, but then I need to get a reference to the current sheet of which there is only one. But no reference that I try will work. They all toss an error '91 Object or With block not set.
After I do the OpenText and make the new workbook, then I need to call a series of subs to do format the data and do some charting. The formatting - recorded from a macro, works just fine, so I know the OpenText call leaves the new data as the active sheet, but I need an object reference to the active sheet to continue with the processing, and I can't get that reference.
The code for the first failing routine looks like this:
Function GetDataRange()
' GetDataRange
' Return the number of rows in the data by looking for the first zero value of the time series
Dim idx As Integer
Dim jdx As Integer
Dim interp As Double
Dim cc As String
Dim Wks As Worksheet ' holds the current worksheet incase we go away from it.
Dim Win As Window ' Holds the currently active window
' Wks = Win.ActiveSheet ' Application.ActiveSheet
Wks = Worksheets(1) ' Application.ActiveSheet
For idx = 10 To 1000
cc = Wks.Cells(idx, 1).Value
If cc = "" Then
Exit For
End If
Next idx
GetDataRange = idx - 1 ' return the row of the last data
End Function
I figure I'm doing something simple and stupid, but in spite of 5 inches of books to look through I can't find a working example of what I need.
Thanks much,
ww
Bookmarks