Autoincrement help

Ramballah

Active Member
Joined
Sep 25, 2018
Messages
334
Office Version
  1. 365
Platform
  1. Windows
Hey so im working on a script where im copying charts everytime and stuff but for every loop i want to autoincrement aka show which loop it is.
in my code below the copy stuff works fine but i just need in the line rng4.Value = "Chart " & (d + i) something changed to make it work but idk how. What it does now is only show the i. it goes from 1 to 5 correctly. but it wont addup the d. Someone please help

Code:
Sub CopyToCorrectRanges()    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim rng1 As Range
    Dim rng2 As Range
    Dim rng3 As Range
    Dim rng4 As Range
    Dim cel As Range
    Dim d As Integer
    Dim i As Integer
    Set rng1 = Range("A1:H102")
    Set rng2 = Range("B3:D102")
    Set rng3 = Range("F3:H102")
    Set rng4 = Range("A1:H1")
    Set cel = Range("B3")
    For d = 0 To 5000
        For i = 0 To 4
            If d = 0 And i = 0 Then i = 1
            If cel.Offset(103 * d, 9 * i) = "" Then
                rng4.Value = "Chart " & (d + i)
                rng1.Copy rng1.Offset(103 * d, 9 * i)
                rng2.ClearContents
                rng3.ClearContents
                rng4.ClearContents
                GoTo TheEnd
            End If
        Next i
    Next d
TheEnd:
Application.Calculation = xlCalculationAutomatic


End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I still haven't figured out how to make it happen and i've been looking on the internet. So please someone come help me :confused:
 
Upvote 0
I'm really not sure why its not working. I even added a new Integer but it still didnt work
Code:
Dim h As Integer


For h = 1 to 5000
rng4.Value = "Chart " & i + h

this didn't work aswell

So to be clear what my macro does is this:

Chart chart chart chart chart
chart chart chart chart chart
chart chart chart chart chart

I want to label them like this:
Chart1 Chart2 Chart3 Chart4 Chart5
Chart6 Chart7 Chart8 Chart9 Chart10
Chart11 Chart12 Chart13 Chart14 Chart15 etc.

What it does now is:
Chart1 Chart2 Chart3 Chart4 Chart5
Chart1 Chart2 Chart3 Chart4 Chart5
Chart1 Chart2 Chart3 Chart4 Chart5

Which i dont want. i want to addup the charts.
 
Upvote 0
I still cant figure out a solution on my own. I have looked up even more but still nothing. Because what i find on google are not within 2 loops really...
 
Upvote 0
You are much more likely to get a response if you explain what you want rather than paste some code that someone has to interpret first.
 
Upvote 0
You are much more likely to get a response if you explain what you want rather than paste some code that someone has to interpret first.
I'm not sure what you mean, i believe i already explained what i want. If there's something not explained just ask
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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