Team, I am trying to loop through an array of specific worksheets with in workbook which are in folder. sheet names may vary as per the request i have. I want the code with dynamic sheet names.
Ex: if i want to loop through only 2 sheet.. let say i want to loop Sheets "Data" and "Matter", code should pull only Data sheet and Matter sheet from all workbooks from a folder to a master file one by one. Next time i want to pull 3 sheets data as per my request and the Sheet names will vary according to my request. So i want to make sheet names list dynamic.
Below is my code which i found..
Thanks in advance and im sorry i haven't explained it as needed.
Ex: if i want to loop through only 2 sheet.. let say i want to loop Sheets "Data" and "Matter", code should pull only Data sheet and Matter sheet from all workbooks from a folder to a master file one by one. Next time i want to pull 3 sheets data as per my request and the Sheet names will vary according to my request. So i want to make sheet names list dynamic.
Below is my code which i found..
Thanks in advance and im sorry i haven't explained it as needed.
VBA Code:
Sub Getdata()
Dim wName As Variant, vName As Variant
Dim Wbk As Workbook 'Set workbook variable don't use ActiveWorkbook
Dim ws As Worksheet
'get folder path
'loop through all xl files in folder
wName = Array("Sheet1", "Sheet3", "Sheet5")
Set Wbk = ThisWorkbook
For Each vName In wName
Set ws = Nothing
On Error Resume Next
Set ws = Wbk.Worksheets(vName)
On Error GoTo 0
If Not (ws Is Nothing) Then
With ws
'my work goes here
End With
End If: Next
End Sub