JeffGrant
Well-known Member
- Joined
- Apr 7, 2021
- Messages
- 516
- Office Version
- 365
- Platform
- Windows
Hi All,
I am trying to modify some vba code supplied by Alan Sidman, thank you Alan .
What I would like to end up with is 3 of each item/name in column A. I think my approach is completely wrong, and would dearly love some direction.
I am trying to modify some vba code supplied by Alan Sidman, thank you Alan .
What I would like to end up with is 3 of each item/name in column A. I think my approach is completely wrong, and would dearly love some direction.
VBA Code:
Option Explicit
Sub CountNames()
Dim i, r As Integer, lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
i = 3
Do Until i = Cells(Rows.Count, 1).End(xlUp).Row
For r = 1 To 3
If Range("A" & i) = Range("A" & i - 1) Then
GoTo Skip
ElseIf Range("A" & i) <> Range("A" & i - 1) And r = 2 Then
GoTo Skip
Else: Range("A" & i).Offset(1, 0).EntireRow.Insert
Range("A" & i).Offset(1, 0) = Range("A" & i)
i = i + 1
End If
Skip:
Next r
i = i + 1
Loop
MsgBox "completed"
End Sub
Book1 | |||
---|---|---|---|
A | |||
1 | Name | ||
2 | Jeff | ||
3 | Jeff | ||
4 | Tom | ||
5 | Tom | ||
6 | Fred | ||
7 | Fred | ||
8 | Fred | ||
9 | Dee | ||
10 | Dee | ||
11 | KT | ||
12 | KT | ||
Sheet1 |