Use Loop

Tron57

Board Regular
Joined
Sep 26, 2002
Messages
66
Because of stack space issues i need to clean my code up, which is posted on the bottom.
Im wondering how to use Looping effectivly the project im working on will need to loop an unkown amount of times, depending on what the raw data is. can you post a few good examples of looping code and explan what is does. (step by setp.
or if you could adjust my below code i think i would learn alot from it, being i could compare what i wrote to what is more efficient.
Sub LoopBlank()
Call FillBlank
End Sub
Sub loopblank2()
If ActiveCell.Offset(1, -1).Value <> "" Then
ActiveCell.Offset(1, 0).Select
Call FillBlank
End If
Application.Run "MacroSheetNEW.xls!Name_or_Contract"
'End If
End Sub

Sub FillBlank()
If ActiveCell <> "" Then
ActiveCell.Offset(1, 0).Select
'Call LoopBlank
End If
If ActiveCell.Offset(0, -1).Value = "Sum:" Then
ActiveCell.Offset(1, 0).Select
Call LoopBlank
End If
If ActiveCell.Offset(0, -1).Value = "Average:" Then
ActiveCell.Offset(1, 0).Select
Call LoopBlank
End If
If ActiveCell.Offset(0, -1).Value = "" Then
ActiveCell.Offset(1, 0).Select
Call loopblank2
End If
If ActiveCell.Offset(0, -1).Value <> "" Then
ActiveCell.Formula = "No Contract"
ActiveCell.Offset(1, 0).Select
Call LoopBlank
End If
End Sub
Sub LoopBlankOLD()
Call FillBlankOLD
End Sub
__________________________________________

different macro but same concept

____________________________________

Sub FillBlankOLD()
ActiveCell.Select
If ActiveCell <> "" Then
ActiveCell.Offset(1, 0).Select
Call LoopBlankOLD
Else
ActiveCell.Select
If ActiveCell.Offset(0, -1).Value = "Sum:" Then
ActiveCell.Offset(1, 0).Select
Call LoopBlankOLD
ElseIf ActiveCell.Offset(0, -1).Value = "Average:" Then
ActiveCell.Offset(1, 0).Select
Call LoopBlankOLD
ElseIf ActiveCell.Offset(0, -1).Value = "" Then
If ActiveCell.Offset(1, -1).Value = "" Then
Application.Run "MacroSheetNEW.xls!OldSkoolTwo" ' calls Old_Format
Else
ActiveCell.Offset(1, 0).Select
Call LoopBlankOLD
End If
ElseIf ActiveCell.Offset(0, -1).Value <> "" Then
ActiveCell.Formula = "No Contract"
ActiveCell.Offset(1, 0).Select
Call LoopBlankOLD
End If
End If
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi there.
Upon looking at your procedures, it is readily apparent why you are having out of stack space errors. I cannot understand what your code is accomplishing. Reply with some info on what your code should do.
Tom
 
Upvote 0

Forum statistics

Threads
1,215,836
Messages
6,127,183
Members
449,368
Latest member
JayHo

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