Related:
- Move cells to the next column
- Clear only the formatting from the selected cell (leaving the content) - Guide
- How do i auto number a column in excel? ✓ - Excel Forum
- Which function is used to compare a cell value to an array of cells and return a value that matches the location of the value in the array, and is used when there are more than two columns in the array ✓ - Excel Forum
- Excel macro to create new sheet based on value in cells - Guide
- How to delete column in word - Guide
1 response
Assumption:
The employee names are in Column A
Private Sub CommandButton1_Click()
Dim i
Dim dup
Dim r
r = Range("A65536").End(xlUp).Row 'This will find the last used row regardless of empty cells
i = 1
Columns("B:B").Select 'You stated creating a column so I assume you want to insert column for the team name
Selection.Insert Shift:=xlToRight
'This will first move the team names beside the person's name and delete the team name.
For i = i To r
If Not IsEmpty(Range("A" & i)) And Right(Range("A" & i), 4) = "team" Then
dup = i
Range("B" & i).Offset(-1, 0) = Range("A" & dup)
Rows(dup).EntireRow.Delete Shift:=xlUp
End If
Next i
i = 1
'Now we can delete the empty rows
Rows(r).Select
For r = r To i Step -1
If Range("A" & r) = "" Then
Rows(r).EntireRow.Delete
End If
Next r
Range("A1").Select
End Sub
The employee names are in Column A
Private Sub CommandButton1_Click()
Dim i
Dim dup
Dim r
r = Range("A65536").End(xlUp).Row 'This will find the last used row regardless of empty cells
i = 1
Columns("B:B").Select 'You stated creating a column so I assume you want to insert column for the team name
Selection.Insert Shift:=xlToRight
'This will first move the team names beside the person's name and delete the team name.
For i = i To r
If Not IsEmpty(Range("A" & i)) And Right(Range("A" & i), 4) = "team" Then
dup = i
Range("B" & i).Offset(-1, 0) = Range("A" & dup)
Rows(dup).EntireRow.Delete Shift:=xlUp
End If
Next i
i = 1
'Now we can delete the empty rows
Rows(r).Select
For r = r To i Step -1
If Range("A" & r) = "" Then
Rows(r).EntireRow.Delete
End If
Next r
Range("A1").Select
End Sub