Hi, I got several sheets with 200+ columns.
For every sheet, I want the macro to check row 6 of a column, and if the row contains a certain value, it
will keep that column but those columns who don't have the value will be deleted.
I have already tried with this script:
Private Sub CommandButton1_Click()
Dim currentColumn As Integer
Dim columnHeading As String
For currentColumn = NMBW.UsedRange.Columns.Count To 1 Step -1
columnHeading = NMBW.UsedRange.Cells(6, currentColumn).Value
'CHECK WHETHER TO KEEP THE COLUMN
Select Case columnHeading
Case "Planned Date Status PR", "PR Drawing Needed SEU", "Planned Serial Order Date SEU", "Serial Order Placed SEU", "Planned PPAP Appr Date SEU"
'Do nothing
Case Else
'Delete if the cell doesn't contain "Homer"
If InStr(1, _
NMBW.UsedRange.Cells(6, currentColumn).Value, _
"Homer", vbBinaryCompare) = 0 Then
NMBW.Columns(currentColumn).Delete
End If
End Select
Next
End Sub
On the fourth line I get error: "Object required"
Can someone explain why?
Bookmarks