Option Explicit Error

B

Bob

Why do I get an error message on "Option Explicit"?

Private Sub CommandButton34_Click()
Option Explicit
Sub testme01()

Dim iRow As Long
Dim HowMany As Long

HowMany = 20

With ActiveSheet
For iRow = 52 To (32 * HowMany - 1) + 52 Step 32
If IsNumeric(.Cells(iRow + 3, "I").Value) Then
If .Cells(iRow + 3, "I").Value > 0 Then
.Cells(iRow, "A").Resize(16, 9).PrintPreview
'.printout when you're done checking
Exit For
End If
End If
Next iRow
End With

Range("A1").Select
End Sub

Thank You,
 
K

Kevin Stecyk

Bob,

Try moving Option Explicit outside the subroutine.

Option Explicit


Private Sub CommandButton34_Click()
Sub testme01()

Dim iRow As Long
Dim HowMany As Long

HowMany = 20

yadda, yadda, yadda,

Regards,
Kevin
 
E

Edwin Tam (MS MVP)

I think you should remove these two lines:

Option Explicit
Sub testme01()

These look useless.


----- Bob wrote: -----

Why do I get an error message on "Option Explicit"?

Private Sub CommandButton34_Click()
Option Explicit
Sub testme01()

Dim iRow As Long
Dim HowMany As Long

HowMany = 20

With ActiveSheet
For iRow = 52 To (32 * HowMany - 1) + 52 Step 32
If IsNumeric(.Cells(iRow + 3, "I").Value) Then
If .Cells(iRow + 3, "I").Value > 0 Then
.Cells(iRow, "A").Resize(16, 9).PrintPreview
'.printout when you're done checking
Exit For
End If
End If
Next iRow
End With

Range("A1").Select
End Sub

Thank You,
 
P

Patrick Molloy

Option Explicit should be the very first line of the code
sheet.

Tip: Under Tools/Options in the Editor tab, make sure
that the checkbox for 'Require Variable Declaration' is
checked...this will add Option Explicit automatically.

Tip: Add
Option Private Module
This means that PUBLIC procedures will not be visible in
Excel's Macro list, but will be available to other modules

Patrick Molloy
Microsoft Excel MVP
 
Top