I have developed a vba for many systems. I am giving examples for 2 systems here:
Private Sub Macro1()
Set x = Workbooks.Open("C:\Users\****\Desktop\New folder\System1.xls")
With x.Sheets("System1")
Set aCell1 = .Range("A1:X1000").Find(What:="User", LookIn:=xlValues,
LookAt:=xlWhole, _MatchCase:=False, SearchFormat:=False)
.Range(aCell1,
.Cells(.Rows.Count,aCell1.Column).End(xlUp)).Offset(2,0).Copy_
ThisWorkbook.Sheets("System1").Range("A2")
End With
Private Sub Macro2()
Set x = Workbooks.Open("C:\Users\****\Desktop\New folder\System2.xls")
With x.Sheets("System2")
Set aCell1 = .Range("A1:X1000").Find(What:="User", LookIn:=xlValues,
LookAt:=xlWhole, _MatchCase:=False, SearchFormat:=False)
.Range(aCell1,
.Cells(.Rows.Count,aCell1.Column).End(xlUp)).Offset(2,0).Copy_
ThisWorkbook.Sheets("System1").Range("A2")
End With
Is there a way through which I can mention all the system name in an array or list instead of writing different subs for different systems? Since the only thing that is getting changed is the system number
Try to add the system as a parameter. In the example below it is an optional one:
And this is how you call it:
Edit: As far as you want array in the original, here is a possible solution, that you can fix using the Macro1 sub from above:
You just need to refactor your code: