I am trying to modify this code to run in a macro that applies it 3 different worksheets in a work book using a different criteria for each sheet...
don't have much of an understanding of VBA, mostly use the recorder... anyway, I must be missing some sort of structural knowledge here, any help would be much appreciated...
Starting with a master sheet, the macro copies it 3 times and names the copies RET, OFF, and IND
For each of these sheets I want to delete all of the columns that do not have the corresponding sheet name in row 1. So for example if cell F1 in the RET sheet does not contain "RET", then I want column F deleted as well as all of the other columns that have values other than "RET" in the first cell. I would like to repeat this for each of the other sheets.
The code I'm trying to work with is
Sub sbDelete_Columns_Based_On_Criteria()
Dim lColumn As Long
Dim iCntr As Long
lColumn = 201
For iCntr = lColumn To 1 Step -1
If Cells(1, iCntr) <> "RET" Then
Columns(iCntr).Delete
End If
Next
End Sub
However I run into problems when I try to reinsert this into the macro for the other sheets with the other criteria... Also, is there any way for lColumn = 201 to auto count how many columns are in the sheet rather than me entering a number, I entered 201 in this case as I figured 201 would usually be more than enough, but maybe not always...
Thanks so much for any help!
Cheers,
Joe
Bookmarks