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 1404 Registration date Thursday July 24, 2014 Status Moderator Last seen September 15, 2023 - Jan 20, 2021 at 05:59 AM
vcoolio Posts 1404 Registration date Thursday July 24, 2014 Status Moderator Last seen September 15, 2023 - Jan 20, 2021 at 05:59 AM
Related:
- Macro to insert row in excel based on criteria
- If cell contains (multiple text criteria) then return (corresponding text criteria) ✓ - Excel Forum
- Excel macro to create new sheet based on value in cells - Guide
- Spell number in excel without macro - Guide
- Macro to copy data from one workbook to another based on criteria ✓ - Excel Forum
- How to change account based in instagram - Instagram Forum
1 response
vcoolio
Posts
1404
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 15, 2023
259
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.