Home » excel » Macro functions to increment value of EXCEL cells

Macro functions to increment value of EXCEL cells

Posted by: admin May 14, 2020 Leave a comment


I am new to Macro programming in Excel.

So far, I was able to create a program that turns


with the following:

Sub CopyData()
Dim lRow As Long
Dim RepeatFactor

    lRow = 1
    Do While (Cells(lRow, "A") <> "")

        RepeatFactor = 5
        If ((RepeatFactor > 1) And IsNumeric(RepeatFactor)) Then

           Range(Cells(lRow, "A"), Cells(lRow, "B")).Copy
           Range(Cells(lRow + 1, "A"), Cells(lRow + RepeatFactor - 1, "B")).Select
           Selection.Insert Shift:=xlDown

           lRow = lRow + RepeatFactor - 1
        End If

        lRow = lRow + 1
End Sub

But now, I am trying to increment the third octet of each IP address up to a certain number, and then repeat.

Here is what I have:

enter image description here

And here is what I would like:

enter image description here

Please tell me what functions I should google ….

How to&Answers:

Instead of using a macro, this can be solved by using simply cell formulas (UDFs) and just copy them down.

A1 = 10
B1 = 10
C1 = 10+MOD(ROW(),4)
D1 = 0+INT(ROW()/4)
E1 = A1 & "." & B1 & "." & C1 & "." & D1

Then copy A1:E1 down….

(Note: Avoid macros! Macros are violating the functional character of a spreadsheet, intransparent (not visible how data is processed), often complicated (just try to read code from others), etc)