Tuesday, November 22, 2016

VBA Macro to Insert Rows based on Cell Value in Excel

Excel VBA Macro to Insert Rows based on Cell Value
Sub InsRows()
Dim X As Integer
Dim Y As Integer
Dim Z As Integer
K = 0

For X = 2 To 100

Y = Cells(X, 1).Value
    
    For Z = 1 To Y
          Cells(X, 1).Offset(1, 0).Rows.Insert
          Cells(X, 1).Offset(1, 0).Interior.ColorIndex = 24    
          K = K + 1
    Next Z

    X = (X + K)
    K = 0
 Next X
End Sub
------------------------------------------------------------------------------------------------
Example:
Suppose we have specified how many rows need to insert a as specified as follows:


Output:
Now the above Macro will insert the rows after each cell as shown below, based on number specified.

Thanks, TAMATAM

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog