Doing MS Training in Excel, having Macro Issue
You have "option explicit" at the top of that module with the code. That means
you're telling VBA that you must declare all the variables that you use--and
that's a good thing.
Option Explicit
Sub CountRows()
Dim x As Long
Dim y As Long
Dim z As Long
x = ActiveCell.Row
y = ActiveCell.Column
z = 0
Do While Cells(x, y).Value < ""
x = x + 1
z = z + 1
Loop
MsgBox "There are " & z & " rows in the current range."
End Sub
The Dim statements declare all 3 of those variables as Long's--whole numbers
between -2,147,483,648 to 2,147,483,647. (I looked at VBA's help!)
Judi<< wrote:
I am trying to work through the online training provided by Microsoft about
Excel 2003 and I have run into an issue with the Macro lesson.
Following the instructions exactly, I have entered this macro in to a module
in the spreadsheet:
Sub CountRows()
x = ActiveCell.Row
y = ActiveCell.Column
z = 0
Do While Cells(x, y).Value < ""
x = x + 1
z = z + 1
Loop
MsgBox "There are " & z & " rows in the current range."
End Sub
When I try to run the macro, it tell me that variable x is undefined. I
tried going into the spreadsheet and placing the focus where they said and
running it from there, but I get the same message.
Please help me understand what I need to do to fix this. I am doing the
training so that I can understand this, but if the training is wrong, how am
I supposed to learn?
Feel free to talk to me like a child, I'm completely new to VBA.
Thank you to all who offer help.
--
Dave Peterson
|