I'm working on a macro that someone else wrote and am confused because they don't define a variable but are still using it. 1) is this possible and 2) how does excel/vba know what the variable is supposed to be? The variable used is "theCell" and there is no definition anywhere. Code below, and thanks:
Sub DoTheWork()
Sheets("All Data").Activate
ActiveSheet.Range("A2").Select
ActiveSheet.Range(Selection, Selection.End(xlDown)).Select
Set homebook = ActiveWorkbook
Set homeSheet = Sheets("All Data")
topRow = 2
Application.ScreenUpdating = False
'Application.ScreenUpdating = True
For Each theCell In Selection
If (theCell.Value <> theCell.Offset(1, 0).Value) Then
Range("A" & topRow & ":AS" & theCell.Row).Select
Sheets("e-TAR").Select
ActiveSheet.Copy
Set copySheet = ActiveSheet
Set copyBook = ActiveWorkbook
Thanks!
Option Explicitat the top of the module containing the code. It's good practise to always use that.