Hello,
I know this must sound childish to VBA pros, but I am trying to automate data import in my workbook. In a nutshell, I'm trying to write code that will:
1) let the user select the source file (already figured out this part);
2) if one of the sheets in the selected source workbook matches the name of the sheet in my target workbook, copy columns A:S and paste them into my target workbook
I've got the following code which works fine but I must specify sheet names for each individual sheets that need to be imported (so, basically repeat the same passage of code over and over again):
Code
For Each ws In ActiveWorkbook.Worksheets
If ws.Name = "Sheet1" Then
ActiveWorkbook.Sheets("Sheet1").Range("A:S").Copy Destination:=ThisWorkbook.Sheets("Sheet1").Range("A:S")
Ideally, I want something along the following lines:
Code
For Each ws In ActiveWorkbook.Worksheets
If ActiveWorkbook.ws.Name = ThisWorkbook.ws.Name Then
ActiveWorkbook.ws.Range("A:S").Copy Destination:=ThisWorkbook.ws.Range("A:S")
Next
Doesn't need to be a ready solution, but maybe you can point me out in the right direction? Thanks!