Making a simple macro to open a series of workbooks, select certain cells out of them and copy to ThisWorkbook
I have it all set up and working, my code works, but I know there has to be a more elegant solution.
The cells I'm copying from are, of course, not in any logical order. Some are contiguous but most are scattered around by the person that created the template.
Essentially what I need to do is:
Now if the Source locations were in some logical format I could do it by Range(), maybe using offset. Heck, I could even reference by Cells(intRow, intCol)
Is there a better way? I started thinking about
This properly creates a bunch of ranges with the locations in them, however I can't figure out how to reference the ranges.
Unfortunately it gives me a type mismatch because I'm trying to pass a string to a Range variable.
So what's the best way of solving this? Thank you very much for your insight!
I have it all set up and working, my code works, but I know there has to be a more elegant solution.
The cells I'm copying from are, of course, not in any logical order. Some are contiguous but most are scattered around by the person that created the template.
Essentially what I need to do is:
Code:
wsSource.Range("B26").copy
wsTarget.Cells(intRow, 2).pastespecial (xlPasteValues)
wsSource.Range("D22").copy
wsSource.Cells(intRow, 3).pastespecial (xlPasteValues)
etc....
Now if the Source locations were in some logical format I could do it by Range(), maybe using offset. Heck, I could even reference by Cells(intRow, intCol)
Is there a better way? I started thinking about
Code:
dim rSource1 as Range
dim rSource2 as Range
etc...
With wsSource
rSource1 = .Range("B26")
rsource2 = .Range("D22")
etc...
End With
This properly creates a bunch of ranges with the locations in them, however I can't figure out how to reference the ranges.
Code:
Dim rSourceCell as Range
For intLoopCount = 1 to XX
rSourceCell = rSource + cstr(intLoopCount)
rSourceCell.Copy
Unfortunately it gives me a type mismatch because I'm trying to pass a string to a Range variable.
So what's the best way of solving this? Thank you very much for your insight!