I have the following procedure that works well but my problem is that I need to have the same procedure run on different worksheets within the same workbook. I have tried Arrays unsuccessfully (as I am not good enough at programming) and resorted to copying the same procedure 8 times for the 8 number of worksheets that I have.
There is zero change in rows, columns and procedures; the only thing that is changing is the worksheet name. I was wondering if someone could lead me down the correct path on how to have an array or other type of procedure so I won’t have 8 separate procedures for EXACTLY the same code. Generally, is there any "bullet proof" way to have a procedures run the exact same code with different worksheets.
One thought was using a variable for the sheet name but that i believe gets back to arrays and my attempts kept failing so i just resorted to copying the below code 8 times and change the worksheet name.
Any help/thoughts appreciated.
There is zero change in rows, columns and procedures; the only thing that is changing is the worksheet name. I was wondering if someone could lead me down the correct path on how to have an array or other type of procedure so I won’t have 8 separate procedures for EXACTLY the same code. Generally, is there any "bullet proof" way to have a procedures run the exact same code with different worksheets.
One thought was using a variable for the sheet name but that i believe gets back to arrays and my attempts kept failing so i just resorted to copying the below code 8 times and change the worksheet name.
Code:
Sub Copy_PasteData()
Dim LRow As Long
Worksheets("REG_DataSrc").Activate '<------this REG_DataSrc will change to MID_DataSrc, etc etc
Worksheets("REG_DataSrc").Range("B10:F100").ClearContents '<-------this REG_DataSrc will change to MID_DataSrc, etc etc
Worksheets("EzeSrc").Activate
With Worksheets("EzeSrc")
LRow = Worksheets("EzeSrc").Cells(.Rows.Count, "M").End(xlUp).Row
'Debug.Print LRow
End With
' new autofilter code to select unique items, copy to sheet
Worksheets("EzeSrc").Range("AH10:AL100").ClearContents
On Error Resume Next
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
'to filter the first list
Worksheets("EzeSrc").Range("M9", Range("Q9").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("AH1:AJ2"), CopyToRange:=Range("AH9:AL9"), Unique:=False
Worksheets("EzeSrc").Range("AH10:AL100").Copy Destination:=Worksheets("REG_DataSrc").Range("B10") '<------this REG_DataSrc will change to MID_DataSrc, etc etc
End Sub
Any help/thoughts appreciated.