Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,543
- Office Version
- 365
- 2016
- Platform
- Windows
I have this range of data ..
(I have intentionally hidden some rows for the ease of presentation)
I need to insert blank rows between two different values in R. For example, between rows 16 and 17 (CR and DR) and 22 and 23 (DR and FR). I am using this code:
The result is a row inserted between every between all rows. Every second row is empty. Data row, empty row, data row, empty row etc...
Excel 2010 | |||
---|---|---|---|
R | |||
13 | CR | ||
14 | CR | ||
15 | CR | ||
16 | CR | ||
17 | DR | ||
18 | DR | ||
19 | DR | ||
20 | DR | ||
21 | DR | ||
22 | DR | ||
38 | FR | ||
39 | FR | ||
MasterWKSH |
I need to insert blank rows between two different values in R. For example, between rows 16 and 17 (CR and DR) and 22 and 23 (DR and FR). I am using this code:
Code:
'** INSERT SEPARATOR ROWS
Dim r As Long, mcol As String, h As Long
' find last used cell in Column A
r = Cells(Rows.Count, "R").End(xlUp).Row
' get value of last used cell in column A
mcol = Cells(r, 1).Value
' insert rows by looping from bottom
For h = r To 2 Step -1
If Cells(h, 1).Value <> mcol Then
mcol = Cells(h, 1).Value
Rows(h + 1).Insert
End If
Next h
The result is a row inserted between every between all rows. Every second row is empty. Data row, empty row, data row, empty row etc...