Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Help with better loop code

Have following code that works but am sure there is a better way:-

UserForm1.Label1.Caption = "Step 2 in progress"
UserForm1.Repaint
Application.StatusBar = "Step 2 in progress"

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual


Check = True: Counter = 0: R = 50 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 1137 ' Inner loop.
R = 50 + Counter 'start row
C = 14 'start Column

If Cells(R - 3, 1).Value = "Y" And Cells(R - 3, 2).Value = 1 Then
Cells(R - 1, C).Clear

If Cells(R, C).Value = 0 Then

If Cells(R - 3, 10).Value = 1 Then
Cells(R - 1, C).Value = (Cells(R - 2, C).Value - Cells(R -
3, C - 2).Value) _
+ ((Cells(R - 2, C + 1).Value) * (Cells(R - 3, 11).Value) /
4)

ElseIf Cells(R - 3, 10).Value = 2 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 3 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 4 Then
"what ever"

Else: Cells(R - 1, C).Value = Cells(R - 3, 9).Value

End If

ElseIf (Cells(R, C).Value < (Cells(R - 2, C + 1).Value) *
(Cells(R - 3, 11).Value) / 4) Then

If Cells(R - 3, 10).Value = 1 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 2 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 3 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 4 Then
"what ever"

Else: Cells(R - 1, C).Value = Cells(R - 3, 9).Value

End If

End If

End If

Counter = Counter + 4 ' Increment Counter.
If Counter 1137 Then ' If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

UserForm1.Label1.Caption = "Step 3 in progress"
UserForm1.Repaint

Application.StatusBar = "Step 3 in progress"

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Check = True: Counter = 0: R = 50 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 1137 ' Inner loop.
R = 50 + Counter 'start row
C = 15 'start Column

If Cells(R - 3, 1).Value = "Y" And Cells(R - 3, 2).Value = 1 Then
Cells(R - 1, C).Clear
If Cells(R, C).Value = 0 Then
If Cells(R - 3, 10).Value = 1 Then
"what ever"

carrys on as same loop above but on next column

Thanks for any guidance

Simon

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Help with better loop code

Perhaps this ?:

Stepno = 1

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

For c = 14 To 20 '<===== Change 20 to Suit

Stepno = Stepno + 1

UserForm1.Label1.Caption = "Step " & Stepno & " in progress"
UserForm1.Repaint
Application.StatusBar = "Step " & Stepno & " in progress"

' For R=50 to 1187 step 4 '<=== Replace "For" statement below and remove
R=50 + counter ????
For counter = 0 To 1137 Step 4 ' Inner loop.
R = 50 + counter 'start row

If Cells(R - 3, 1).Value = "Y" And Cells(R - 3, 2).Value = 1 Then
Cells(R - 1, c).Clear

If Cells(R, c).Value = 0 Then

If Cells(R - 3, 10).Value = 1 Then
Cells(R - 1, C).Value = (Cells(R - 2, C).Value - Cells(R -
3, C - 2).Value) _
+ ((Cells(R - 2, C + 1).Value) * (Cells(R - 3, 11).Value) /
4)

ElseIf Cells(R - 3, 10).Value = 2 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 3 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 4 Then
"what ever"

Else: Cells(R - 1, c).Value = Cells(R - 3, 9).Value

End If

ElseIf (Cells(R, c).Value < (Cells(R - 2, c + 1).Value) * (Cells(R -
3, 11).Value) / 4) Then

If Cells(R - 3, 10).Value = 1 Then



ElseIf Cells(R - 3, 10).Value = 2 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 3 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 4 Then
"what ever"

Else: Cells(R - 1, c).Value = Cells(R - 3, 9).Value

End If

End If

End If
Next counter
' Next R <=== if Counter loop is removed
Next c

"Sliman" wrote:

Have following code that works but am sure there is a better way:-

UserForm1.Label1.Caption = "Step 2 in progress"
UserForm1.Repaint
Application.StatusBar = "Step 2 in progress"

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual


Check = True: Counter = 0: R = 50 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 1137 ' Inner loop.
R = 50 + Counter 'start row
C = 14 'start Column

If Cells(R - 3, 1).Value = "Y" And Cells(R - 3, 2).Value = 1 Then
Cells(R - 1, C).Clear

If Cells(R, C).Value = 0 Then

If Cells(R - 3, 10).Value = 1 Then
Cells(R - 1, C).Value = (Cells(R - 2, C).Value - Cells(R -
3, C - 2).Value) _
+ ((Cells(R - 2, C + 1).Value) * (Cells(R - 3, 11).Value) /
4)

ElseIf Cells(R - 3, 10).Value = 2 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 3 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 4 Then
"what ever"

Else: Cells(R - 1, C).Value = Cells(R - 3, 9).Value

End If

ElseIf (Cells(R, C).Value < (Cells(R - 2, C + 1).Value) *
(Cells(R - 3, 11).Value) / 4) Then

If Cells(R - 3, 10).Value = 1 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 2 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 3 Then
"what ever"

ElseIf Cells(R - 3, 10).Value = 4 Then
"what ever"

Else: Cells(R - 1, C).Value = Cells(R - 3, 9).Value

End If

End If

End If

Counter = Counter + 4 ' Increment Counter.
If Counter 1137 Then ' If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

UserForm1.Label1.Caption = "Step 3 in progress"
UserForm1.Repaint

Application.StatusBar = "Step 3 in progress"

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Check = True: Counter = 0: R = 50 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 1137 ' Inner loop.
R = 50 + Counter 'start row
C = 15 'start Column

If Cells(R - 3, 1).Value = "Y" And Cells(R - 3, 2).Value = 1 Then
Cells(R - 1, C).Clear
If Cells(R, C).Value = 0 Then
If Cells(R - 3, 10).Value = 1 Then
"what ever"

carrys on as same loop above but on next column

Thanks for any guidance

Simon


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop for VBA code? paulinoluciano Excel Worksheet Functions 5 December 28th 05 01:30 PM
Loop Code sheeba Excel Programming 0 December 4th 05 06:12 AM
How to Loop some code Phil Osman Excel Discussion (Misc queries) 2 August 19th 05 11:14 AM
How to get my code to loop Dominique Feteau[_2_] Excel Programming 5 December 17th 04 01:35 PM
Help with loop code... gaba Excel Programming 1 October 20th 04 01:37 PM


All times are GMT +1. The time now is 08:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"