View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Doing MS Training in Excel, having Macro Issue

You probably have an 'Option Explicit' line at the top of the code module
(before and outside of any procedure). This tells the compiler that all
variables must be explicitly declared with the 'Dim' statement before they
can be used in code. Thus, you need to declare your variables with code like

Dim x As Long 'or As whatever type is appropriate

If you omit the Option Explicit declaration (a very bad habit to get into),
the compiler will create an instance of the variable when it is first
encountered in code. So, you can do either of two things: remove the 'Option
Explicit' statement (bad idea), or explicitly declare the variables using
the 'Dim' statement (good idea).


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




"Judi<<" wrote in message
...
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.