Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skiping Lines in my macro

Status
Not open for further replies.

JohnAcc

Technical User
Aug 13, 2003
143
GB
Hi There,

I have a fairly lengthy macro that is split across many modules. It was running fine but all of a sudden the macro skips several lines of code and ends itself. I have checked my code and there is no obvious reason for it to do this.

My Code always drops to the end of the sub at the following point:

Public Sub Change_Main_Graph()

Set My8thRng = Range("PLAT_Ins_Penetration")
Set My8thName = Range("PLAT")
Populate_Multi_Stacked_Graphs ' Populate the graph

Public Sub Populate_Multi_Stacked_Graphs()
DoEvents
Img_On ' Turn the key labels on

Public Sub Img_On
ImgKey.Visible = True ' THE CODE STOPS HERE ?????????
Set Key = Array(Image5, Image6, Image7,
Image8,Image9,Image10, Image11, Image12)
ETC.......


Does anyone have ideas on why this stops the code. Any help would be greatly appreciated ?

Cheers






 
It is difficult (if not impossible) to help you when you provide incomplete code and don't indicate where the gaps are. If the code is indeed as you have posted, then the processing would stop much sooner. (No "End Sub" statements.)

Here are a couple of things you can do to help yourself:

1. Put this statement at the top of each code module:
[blue]
Code:
    Option Explicit
[/color]

2. Select "Debug / Compile VBAProject" from the menu and try to understand and correct the problems as they are reported.

Here is another tip. It looks like your code is organized as a chain of subroutine calls:
Code:
Sub A
  Call B
End Sub

Sub B
  Call C
End Sub

Sub C
  Call D
End Sub
This is difficult to understand and maintain. Consider re-structuring the logic so that the code looks like this instead:
Code:
Sub Main
  Call A
  Call B
  Call C
  Call D
End Sub

Sub A
[green]
Code:
 ' Do Sub A stuff
[/color]
Code:
End Sub

Sub B
[green]
Code:
 ' Do Sub B stuff
[/color]
Code:
End Sub

etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top