I have tried to write code to delete all cols except certain specified cols
The Cols to be retained are as follows
"Branch Name", "Title", "Initials", "First Name", "Last Name", "ID Type", "ID Number", "Birth Date", "Gender"
Sub Delete_Cols()
Dim k, i As Long, s As String
k = Intersect(ActiveSheet.UsedRange, Rows(1))
For i = UBound(k, 2) To 1 Step -1
Select Case LCase$(k(1, i))
Case "Branch Name", "Title", "Initials", "First Name", "Last Name", "ID Type", _
"ID Number", "Birth Date", "Gender"
'do nothing
Case Else
s = s & "," & Cells(1, i).Address(0, 0)
End Select
Next
If Len(s) > 1 Then
s = Mid$(s, 2)
ActiveSheet.UsedRange.Range(s).EntireColumn.Delete
End If
End Sub
however when running the code , I get a run time error "Application-defined or object defined error" and code below is highlighted
ActiveSheet.UsedRange.Range(s).EntireColumn.Delete
it would be appreciated if someone could amend my code
Bookmarks