Macro to insert row based on variable cell value (text)
Closed
deadxcell
Posts
1
Registration date
Tuesday 19 January 2021
Status
Member
Last seen
19 January 2021
-
19 Jan 2021 à 13:39
vcoolio Posts 1411 Registration date Thursday 24 July 2014 Status Contributor Last seen 6 September 2024 - 20 Jan 2021 à 05:59
vcoolio Posts 1411 Registration date Thursday 24 July 2014 Status Contributor Last seen 6 September 2024 - 20 Jan 2021 à 05:59
Related:
- Based on the value in cells b77
- Based on the values in cells b77 b81 ✓ - Excel Forum
- Based on the values in cells b77 ✓ - Excel Forum
- Based on the cell values in cells b77 ✓ - Excel Forum
- Excel function question - Excel Forum
- Based on the values in cells b77 b88 ✓ - Excel Forum
1 response
vcoolio
Posts
1411
Registration date
Thursday 24 July 2014
Status
Contributor
Last seen
6 September 2024
262
20 Jan 2021 à 05:59
20 Jan 2021 à 05:59
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.