stevenblanc
Registered User.
- Local time
- Today, 12:11
- Joined
- Jun 27, 2011
- Messages
- 103
[SOLVED] Variable not Defined: Sheet and/or Worksheet
Hey folks,
Not entirely sure whats going on. I keep getting the 'variable not defined error' in the following code:
The error is on the bolded 'sheet' above. I tried changing it to worksheet and I get the same error. I'm fairly certain when I saved the file yesterday afternoon it was working perfectly. I have no idea what has cracked.
Any ideas?
Steven
Hey folks,
Not entirely sure whats going on. I keep getting the 'variable not defined error' in the following code:
Code:
Sub Aggregate_Click()
Dim MyPath, MyFilename As String
Dim vNames() As Variant
Dim i, intSheetCount As Integer
If Worksheets(1).Cells(14, 15).Value = "1" Then intSheetCount = 2
If Worksheets(1).Cells(14, 15).Value = "2" Then intSheetCount = 8
Call ClearImportData
MyPath = Worksheets(1).Cells(14, 5).Value
' Add a slash at the end of the path if needed.
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If
MyFilename = Dir(MyPath & "*.xl*")
Do While MyFilename <> ""
Workbooks.Open Filename:=MyPath & MyFilename, ReadOnly:=True
i = -1
For Each [B]Sheet[/B] In ActiveWorkbook.Sheets
If Sheet.Index > intSheetCount Then
i = i + 1
ReDim Preserve vNames(i)
vNames(i) = Sheet.Name
End If
Next
Application.DisplayAlerts = False
ActiveWorkbook.Sheets(vNames).Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Application.DisplayAlerts = True
Workbooks(MyFilename).Close savechanges:=False
MyFilename = Dir()
Loop
' This procedure will ensure that all links to Department Guidelines are re-routed to this workbook.
' Call ChangeLinks
Call BreakLinks
End Sub
The error is on the bolded 'sheet' above. I tried changing it to worksheet and I get the same error. I'm fairly certain when I saved the file yesterday afternoon it was working perfectly. I have no idea what has cracked.
Any ideas?
Steven
Last edited: