I'm writing a macro to do a complex copy/paste exercise. It's pretty straightforward conceptually, but I'm stuck in one spot. All of the various blocks of data are identified with various named ranges. I need iterate through this list of names, passing each name as an argument to a function (actually a subroutine, but same idea). The source of the data is in one workbook while the destination is in another workbook.
Here is what I have (for just one block of data):
Private Sub copyABU()
copyPaste(ThisWorkbook.Names("myRange1").RefersToRange)
copyPaste(ThisWorkbook.Names("myRange2").RefersToRange)
copyPaste(ThisWorkbook.Names("myRange3").RefersToRange)
//etc
End Sub
Private Sub copyPaste(thisRange As Range)
Windows(someworkbook).Range(thisRange).Copy
Range(thisRange).PasteSpecial Paste:=xlPasteValues
End Sub
Unfortunately, I get a run-time error on this. I think that there is a type mismatch, but I'm not sure about this and can't figure out what I am missing. Can anyone see why this fails? (I'm using Excel 2010).
Thanks!