Not looping

Ramballah

Active Member
Joined
Sep 25, 2018
Messages
311
Office Version
  1. 365
Platform
  1. Windows
Hello all,
Can someone please tell me why my code is not looping?
It should be looping normally but it's not.

Code:
Sub AddCorrectRanges()    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim rng1 As Range
    Dim rng2 As Range
    Dim rng3 As Range
    Dim rng4 As Range
    Dim rng5 As Range
    Dim cel As Range
    Dim i As Integer
    Dim d As Integer
    Set rng1 = Range("G2:J27") 'Entire chart
    Set rng2 = Range("I3:J14") 'Values for statistics
    Set rng3 = Range("I19:J27") 'Values for profits / losses
    Set rng4 = Range("G2:J2") 'Current Session Statistics
    Set rng5 = Range("G18:J18") 'Current Session Profits / Losses
    Set cel = Range("I3")
    For d = 0 To 5000
        For i = 0 To 4
            If d = 0 And i = 0 Then i = 1
            If cel.Offset(30 * d, 5 * i) = "" Then
                rng4.ClearContents
                rng5.ClearContents
                rng4.Value = "Session Statistics " & i + d * 5
                rng5.Value = "Session Profits / Losses " & i + d * 5
                rng1.Copy rng1.Offset(30 * d, 5 * i)
                rng2.Offset(30 * d, 5 * i).ClearContents
                rng3.Offset(30 * d, 5 * i).ClearContents
                rng2.Copy
                rng2.Offset(30 * d, 5 * i).PasteSpecial xlPasteValues
                rng3.Copy
                rng3.Offset(30 * d, 5 * i).PasteSpecial xlPasteValues
                rng4.ClearContents
                rng5.ClearContents
                rng4.Value = "Current Session Statistics"
                rng5.Value = "Current Session Profits / Losses"
                GoTo TheEnd
            End If
        Next i
    Next d
TheEnd:
Application.Calculation = xlCalculationAutomatic
End Sub
 
Why are you looping if you only want something to happen once when you run this code?
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
8tBViM.jpg

So this is the chart that i need to get copied with my code. this chart changes dependant on the master sheet where i change values.
ORpXxE.jpg

Now here you see on the left a code i already had which did just that but in a different sheet with a different chart. It works perfect. On the right you see the code i use for this chart its literally the same but just a bit more of copying and clearing. but this one doesnt work and the F8 doesn't give any errors or anything.
(PS the bottom 2 codes are just for clearing the sheets because this is a test workbook)
Now please someone help me
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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