Hi everyone this is the first time i post anything, i'm trying to execute a code in vba but it doesn't do the job, it's supposed to loop through all worksheets starting from the fourth one, and delete the columns that don't match the sheet's name starting from the sixth column
can someone please help me
Sub sbDelete_Columns_IF_Cell_Cntains_String_Text_Value()
Dim lColumn As Long
Dim iCntr As Long
lColumn = 12
For Each ws In ActiveWorkbook.Worksheets
If ws.Index > 3 Then
For iCntr = lColumn To 6 Step -1
If Cells(1, iCntr) <> ActiveSheet.Name Then
Columns(iCntr).Delete
End If
Next
End If
Next
End Sub
can someone please help me
Sub sbDelete_Columns_IF_Cell_Cntains_String_Text_Value()
Dim lColumn As Long
Dim iCntr As Long
lColumn = 12
For Each ws In ActiveWorkbook.Worksheets
If ws.Index > 3 Then
For iCntr = lColumn To 6 Step -1
If Cells(1, iCntr) <> ActiveSheet.Name Then
Columns(iCntr).Delete
End If
Next
End If
Next
End Sub