I have multiple sets of sheets that interact with one another.
For example:
FS_Franch copy pastes values to FS_Franch_CPV
ItemWide_Operator copy pastes values to ItemWide_Operator_CPV
ItemWide copy pastes values to ItemWide_CPV
To clean up my code, I would like to be able to create a loop such that it performs these operations to each pair of sheets. I know in Stata it is possible to write code such as:
"foreach x of varlist FS_Franch ItemWide_Operator". However, I can't seem to find similar loop capabilities in VBA. Could someone please help enlighten me?
Example code across a pair of sheets:
Note: The cells will always remain the same across all pairs of sheets. The only thing that will be different is the name of the sheets. THANKS
Sheets("FS_Franch").Select
Range("P5:AB269").Select
Selection.Copy
Sheets("FS_Franch_CPV").Select
Range("A1:M265").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
' Sorts table
ActiveWorkbook.Worksheets("FS_Franch_CPV").ListObjects("FS_Franch_CPV_Table").Sort. _
SortFields.Clear
ActiveWorkbook.Worksheets("FS_Franch_CPV").ListObjects("FS_Franch_CPV_Table").Sort. _
SortFields.Add Key:=Range("FS_Franch_CPV_Table[[#All],[Percentile]]"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("FS_Franch_CPV").ListObjects("FS_Franch_CPV_Table").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Bookmarks