OzGrid

How to add rows and specific text after changes in data

< Back to Search results

 Category: [Excel]  Demo Available 

How to add rows and specific text after changes in data

 

Requirement:

 

The user has a data set that comprises of hundreds of different numbers in column "A". The user needs to insert two rows after every change in character and add in specific text as well, i.e. the user has 20 rows with 5505 that then changes to 6606.

 

The user is using the code below which is working but only adds one row with the text exactly where needed but the user needs a second row added with the exact same text & location.

 

Sub blankRows()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If Range("A" & i).Value <> Range("A" & i - 1).Value Then
Rows(i).Insert
Cells(i, 32) = "AL2 2DQ"
End If
Next i
End Sub

 

Solution:

 

Code:

 

https://www.ozgrid.com/COMET/editPage.php?page=1408

 

Obtained from the OzGrid Help Forum.

Solution provided by Mumps.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to use a macro to copy data from multiple workbooks to one master sheet in another workbook
How to copy data from multiple workbooks into one
How to copy data in VBA from different named workbook each time
How to use a macro to pull every Nth row of data

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions. Potenzmittel rezeptfrei


Gallery



stars (0 Reviews)