Macro to insert row based on variable cell value (text)
Closed
deadxcell
Posts
1
Registration date
Tuesday January 19, 2021
Status
Member
Last seen
January 19, 2021
-
Jan 19, 2021 at 01:39 PM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - Jan 20, 2021 at 05:59 AM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - Jan 20, 2021 at 05:59 AM
Related:
- Macro to insert row in excel based on criteria
- Insert gif in excel - Guide
- Insert draft watermark in word on all pages - Guide
- Excel macro to create new sheet based on value in cells - Guide
- How to insert photo in word for resume - Guide
- Number to words in excel - Guide
1 response
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
Jan 20, 2021 at 05:59 AM
Jan 20, 2021 at 05:59 AM
Hello Deadxcell,
You could use a Do/While loop as follows:-
I'm assuming that your data starts in Row2 with headings in Row1.
The code works based on separating the data on the text (names) in Column D.
As I don't know what your sheet name is, I've used the sheet code (Sheet1) to fully qualify your "working sheet" in the code above.
I hope that this helps.
Cheerio,
vcoolio.
You could use a Do/While loop as follows:-
Sub Test() Dim Rw As Long Dim Rng As Range Set Rng = Sheet1.Range("A2") '---->Headings in Row1, data starts in Row2. Else, Rng = Sheet1.Range("A1") Rw = Rng.Row Do If Sheet1.Cells(Rw + 1, 4) <> Sheet1.Cells(Rw, 4) Then Sheet1.Cells(Rw + 1, 4).EntireRow.Insert Rw = Rw + 2 Else Rw = Rw + 1 End If Loop While Not Sheet1.Cells(Rw, 4) = vbNullString End Sub
I'm assuming that your data starts in Row2 with headings in Row1.
The code works based on separating the data on the text (names) in Column D.
As I don't know what your sheet name is, I've used the sheet code (Sheet1) to fully qualify your "working sheet" in the code above.
I hope that this helps.
Cheerio,
vcoolio.