Hi, I am new to excel and after teaching myself have made a code that will copy a set of data from a table into templates, then the data from these templates are copied into new workbooks. The workbooks already exist, and their filepaths are contained in cell values within the main spreadsheet (ThatFile) which I'm running the macro from (ThisFile).
There are 20 repetative stages in my macro. It works fine, but I was seeing if it could be looped. I am having trouble coming up with a code that will loop the below instruction and use the values in various columns within the table of ThisFile.
Here are 2 from the 20, the increment just goes down one for each of the 5 columns as you can see. I think the trouble is getting it to go back ThisFile each time so it is referencing the correct cell values.
ThisFile = "Data to be input to template Macro.xlsm"
ThisSheet = Range("D2").Value
ThisRange = Range("E2").Value
ThatFile = Range("G2").Value
ThatSheet = Range("H2").Value
ThatRange = Range("I2").Value
Windows(ThisFile).Activate
Sheets(ThisSheet).Select
Range(ThisRange).Select
Selection.Copy
Windows(ThatFile).Activate
Sheets(ThatSheet).Select
Range(ThatRange).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Windows("Data to be input to template Macro.xlsm").Activate
Sheets("Related Workbooks").Select
ThisFile = "Data to be input to template Macro.xlsm"
ThisSheet = Range("D3").Value
ThisRange = Range("E3").Value
ThatFile = Range("G3").Value
ThatSheet = Range("H3").Value
ThatRange = Range("I3").Value
Windows(ThisFile).Activate
Sheets(ThisSheet).Select
Range(ThisRange).Select
Selection.Copy
Windows(ThatFile).Activate
Sheets(ThatSheet).Select
Range(ThatRange).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
I've tried lots of different looping techniques but I might just cut my losses and leave it as an uber long macro! But I would like to further my knowledge of excel so any help from anyone would be most welcome.
Happy New Year!!![]()
TommyToe,
Welcome to the forum!
Unfortunately, we can't help you until you use code tags. Check the forum rules (link in my sig) for how
Hope that helps,
~tigeravatar
Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks