next without For - help please?

jayd4wg

Board Regular
Joined
Mar 25, 2005
Messages
197
Code:
For Each cell In [Data!a5:a279999]
    If cell.EntireRow.Hidden = False Then
        pm_name = cell.Offset(0, 7)

'define variables values in subroutine def_Vars
    def_Vars
'catch end of document to exit loop
        If pm_name = "" Then
            Exit For
        End If
'write the placemark info to file #1
'if account is not parent then write folder closing statements to kml and set trigger to only write it once
'then write as child folder output
    If pm_par = 0 Then
    write_folderClose
    End If
    write_pmOutput
        
Next cell
'write footer to file
Print #1, "</folder>"
Print #1, "</Document>"
Print #1, "</kml>"

Close #1
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


the write_folderClose sub is to write a one time bit of code to close out a kml folder (for google earth)

Code:
Sub write_folderClose()
If parent_Trigger = True Then
Print #1, "</folder>"
Print #1, "<folder><name>Child Accounts</name><open>0</open>"
Else
parent_Trigger = False
End If

End Sub

the write_pmOutput sub has nothing more in it than a bunch of print statements to write the KML code for a bunch of variables collected from the spreadsheet.

it befuddles me as to how i'm losing the for/next relationship...any thoughts? This macro is failing to compile because of a next without for error. i'm STUMPED :(
 
Last edited:
I do so miss my javascript tool that would show the start/end relationship of these arguments...it made troubleshooting these easy.

what happened in the example above is that in my cut and paste haste, i grabbed the end if along with some other code that went into another sub...once you called my attention to that i was able to change focus and found the end if hiding in another subroutine and it all makes sense now.

This KML macro is becoming the cat's meow here at work...and luckily i think i'm the only one in the company (hahah!) that even knows how to get to the VBA editor much less can poke my way thru some code with the occasional excuse to use some Google-Fu to get some of the easier answers. I really do use this forum as a last resort because i know i'll get the answer. i try hard to figure things out before i engage you guys. I do appreciate your help!
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I do so miss my javascript tool that would show the start/end relationship of these arguments...it made troubleshooting these easy.

what happened in the example above is that in my cut and paste haste, i grabbed the end if along with some other code that went into another sub...once you called my attention to that i was able to change focus and found the end if hiding in another subroutine and it all makes sense now.

This KML macro is becoming the cat's meow here at work...and luckily i think i'm the only one in the company (hahah!) that even knows how to get to the VBA editor much less can poke my way thru some code with the occasional excuse to use some Google-Fu to get some of the easier answers. I really do use this forum as a last resort because i know i'll get the answer. i try hard to figure things out before i engage you guys. I do appreciate your help!


You're Welcome
 
Upvote 0
I have found this discussion on If ...End If's quite fascinating. I believe that it will come in handy for me in the future. As I am just starting out myself I have significant problems with structuring my code and getting the syntax correct. I believe this knowledge will be beneficial later on. Thanks for the knowledge/help. I look forward to using it in the near future.
 
Upvote 0
I have found this discussion on If ...End If's quite fascinating. I believe that it will come in handy for me in the future. As I am just starting out myself I have significant problems with structuring my code and getting the syntax correct. I believe this knowledge will be beneficial later on. Thanks for the knowledge/help. I look forward to using it in the near future.



. The very fundamental loop stuff has tripped me up as a beginner a few times now. (here’s a bit of recent stuff along those lines (In order of readability!!!…I’m just getting the hang myself of structuring Codes…. and this Forum Format!!))
http://www.mrexcel.com/forum/excel-questions/791019-having-troubl-if-else-if.html#post3869194
http://www.mrexcel.com/forum/excel-...-do-while-loop-end-condition-can-changed.html
http://www.mrexcel.com/forum/excel-...%3D-y-%96-1-usedrange-rows-count-anomale.html
 
Upvote 0
another REALLY useful hint that i have gotten away from somewhat is COPIOUS amounts of comments in your code while developing it. You can label the start/end relationship of loop coding with a simple comment line...this is a piece of advice I need to get back in the habit of using.
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,858
Members
449,194
Latest member
HellScout

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