I need to change the row reference in hundreds of 6 sets of rows of formulae because the column references are different for each row in a set and the row references will be constant for each row in a set of 6, but then increment by 1 per each set of 6 rows. If the formulae are copied down, they will be incorrect and the row references would have to manually amended.
I have therefore written the script as below to replace the row number in each set of rows so that the next incremented number is the replacement row number reference. I know this would be much more efficient if I used array references instead, but attempted and cannot implement it correctly.
Could anyone advise, please?
Thanks
I have therefore written the script as below to replace the row number in each set of rows so that the next incremented number is the replacement row number reference. I know this would be much more efficient if I used array references instead, but attempted and cannot implement it correctly.
Could anyone advise, please?
Thanks
VBA Code:
Sub IncrementRowNumbers()
Dim ws As Worksheet
Dim i As Integer
Dim rowNum As Integer
Dim replaceNum As Integer
Sheets("All Data").Activate
'First line of data
replaceNum = 6
'Start at row 2
For i = 2 To 3001 Step 6
'Loop through the rows within the set of 6 rows
For rowNum = i To i + 5
'Replace "6" with the next iteration
Range("A" & rowNum).Formula = Replace(Range("A" & rowNum).Formula, "6", replaceNum)
Range("B" & rowNum).Formula = Replace(Range("B" & rowNum).Formula, "6", replaceNum)
Range("C" & rowNum).Formula = Replace(Range("C" & rowNum).Formula, "6", replaceNum)
Range("F" & rowNum).Formula = Replace(Range("F" & rowNum).Formula, "6", replaceNum)
Range("G" & rowNum).Formula = Replace(Range("H" & rowNum).Formula, "6", replaceNum)
Next rowNum
'Increment the replacement number by 1 per each set of 6 rows
replaceNum = replaceNum + 1
Next i
End Sub