In short, I have a sheet with about 30 different columns in. The order of these columns can vary from month to month.
I also have a table which has a list of the column names in, but in a specific order.
The following code works fine for one column (I replace CUSTOMNAME with the column header), but rather than doing this 30 times is there a way to loop through all the columns based on the ordering and names in my separate table?
Thanks guys
I also have a table which has a list of the column names in, but in a specific order.
The following code works fine for one column (I replace CUSTOMNAME with the column header), but rather than doing this 30 times is there a way to loop through all the columns based on the ordering and names in my separate table?
Thanks guys
Code:
'Filter column to show Y's
Dim rngSL As Range
Set rngSL = Range("A1:CI" & Cells(Rows.Count, "A").End(xlUp).Row)
SL = WorksheetFunction.Match("[B]CUSTOMNAME[/B]", rngSL.Rows(1), 0)
rngSL.AutoFilter Field:=SL, Criteria1:="Y"
'Copy LOCATIONID and MAINSERVICE into CQC Matched sheet and paste at the bottom
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("CQC matched").Select
Range("A1").Select
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Offset(1, 1).Select
ActiveCell.Select
ActiveCell.FormulaR1C1 = "[B]CUSTOMNAME[/B]"
'Delete out the rows which have just been matched
Sheets("CQC working").Select
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
'Remove filter
ActiveSheet.ShowAllData