Simple code lines failing; error 9 confusion, For without Next...with next

mikecox39

Active Member
Joined
Mar 5, 2014
Messages
251
Office Version
  1. 365
Platform
  1. Windows
I am testing; in the Immediate pane of the VBE, some of the example code in a book I am studying; in order to learn VBA.

Here are a couple that fail every time.



show.php
[/URL][/IMG]

I checked the Help option for error 9 but I didn’t understand it.

I’ve double checked the code; to make sure I entered it exactly as it is in the text, but it fails every time.

show.php
[/URL][/IMG]

This one has a "for" so why am I getting this error? Again, I double checked the example in the text and I have it written exactly as shown in the text.

Others, like “…comments.count” and “…Parent.address” work just fine.
 
I agree with Norie -- I use the Immediate window a LOT, but not to write programs :eeek:
 
Upvote 0
mikecox39,

Thanks for posting all these, I have bookmarked the reply for future reference.

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0
In the Immediate window:

Code:
For Each cmt in Activesheet.comments: msgbox cmt.parent.address & " " & cmt.text: Next cmt

Ok, I guess the author didn't expect the reader to try his example in the Immediate pane. Now that I realize code placed there should be on one line I won't try mult lines of code there again. I guess that's why the ones what worked worked; because they were one line.
 
Upvote 0
I thought I was being clear,

I was referring to the axiomatic one liner; the general statements of obvious truth with nothing else. If you had continued with something like "you can't put multiple lines of code in the immediate pane" I wouldn't have had to wait for that gem to be revealed in your follow up to my crack about your one liner.

you can use it for multiline code blocks if you use the method shg posted, but I don't really see the point.

Why not stick the code in a temp sub?

Then you can loop through it (F8), examine the variables (Watch/Locals windows), set breakpoints, compile the code...

As I indicated at the outset; I'm a novice, I'm just learning about the VBE; what the panes are called and what is in them and what objects are, etc. I don't know what the shg method is, or what temp sub means or how to loop through it using F8.

PS 'all that'? My posts weren't exactly verbose.:smile:

No, but there were a lot of one liners. :laugh:
 
Upvote 0
If you want to test code you can create a subroutine and put the code in it.

That gives the advantage of being able to use various debugging tools.

For example you can step through the code line by line using F8, checking what's happening, variable values, code flow etc.

Once you're done testing the code you can simply delete the subroutine, hence 'temporary' subroutine.
 
Upvote 0
I don't get it:???:

Ok, I realized what this was about too late to edit it so I'll just say... I knew what the abbreviations stood for; that's obvious, I just don't know what a Temporary sub-routine is.

I know what a sub-routine is, everyone who's ever studied BASIC; and how hasn't, knows that. I also know what temporary is, I just don't know where to create a temporary subroutine; do you do it in the immediate pane or somewhere else? What is the syntax or how do you lay it out. Is it just a sub/end sub that you call temporary; to test a line a code; isn't that what the immediate pane is for?

Like I said; I'm a novice. I know how to drive a car but I've never driven this one; so I don't know where all the buttons are; I know what they do, I just need to discover how this car drives.

I think I should just continue my reading, I'm sure it will all fall into place soon. I've gotten a lot of great resources from everyone here, and I've found a new reference that I ordered yesterday; so I think I'm good to go.

I really appreaciate all the help I've gotten on this question; this is a really great forum !
 
Upvote 0

Forum statistics

Threads
1,226,832
Messages
6,193,211
Members
453,780
Latest member
Nguyentam2007

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