Need VBA help with "Compile error: Variable not defined"

Mark Carlson

New Member
Joined
May 27, 2008
Messages
7
This is my first post. Greetings from Athens, TX!

I've used Excel for many years, but finally am learning VBA, using Excel Progamming for Dummies by John Walkenbach. Excel is version 2000.

I've searched extensively on Google and on the MrExcel site for the solution to my problem, but still haven't found it :confused:. Any direction would be most appreciated.

I'm trying to execute the examples in the book, and have gotten the error message "Compile error: Variable not defined" with "MyString =" highlighted with several of the examples. Could someone please tell me where I'm going astray?

Following is the latest subroutine I typed into the module, from page 124:

Option Explicit

Sub GetLength()
MyString = "Hello World"
StringLength = Len(MyString)
MsgBox StringLength
End Sub

Thank you for your help!

Mark Carlson
 
Greg,

That worked fine! Thank you so much.

When you said, "The code tags are what I used above to make the code line stand out.", I don't see what you are referring to.

Thanks again, Mark
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I'm not Greg! :)
When posting code if you prefix it with a [ code ] tag (without the spaces) and terminate it with a [ / code ] tag (again without spaces), it gets proper formatting. For example, if you enter:
[ code ]here is some code[ / code ]
without the spaces in the tags, you get:
Code:
here is some code

Regards,
Rory
 
Upvote 0
Thanks, Rory,

I didn't even notice that a new person was in the thread!


What do you mean by, "to make the code line stand out"?

Thanks again, Mark
 
Upvote 0
Without code tags, my post would have looked like this:

Dim MyString As String, StringLength as Long


as opposed to this:
Code:
Dim MyString As String, StringLength as Long
 
Upvote 0

Forum statistics

Threads
1,217,302
Messages
6,135,721
Members
449,959
Latest member
choy96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top