Hi guys,
I've been trying to copy values from one range to another, and the ranges need to be dynamic. Normally I use a combination of the 'range' and 'cells' properties, like this:
range(cells(1,1),cells(x,y)).value = range(cells(2,3),cells(a,b).value
or something similar, and it works fine.
However, when I try to do this across two workbooks I get a runtime error. I've isolated the piece of code causing the problem as here:
Sub test()
Dim count As Integer
count = 15
Workbooks("Output Library").Sheets("Standard Sheet (2)").Range(Cells(1, 1), Cells(count, 3)).Value = _
Workbooks("Excel Front End v1.2").Sheets("Inputs to Vensim").Range(Cells(1, 1), Cells(count, 3)).Value
End Sub
The thing that confuses me is that if I change the range references to a1 style then it works fine:
Sub test()
Dim count As Integer
count = 15
Workbooks("Output Library").Sheets("Standard Sheet (2)").Range("A1").Value = _
Workbooks("Excel Front End v1.2").Sheets("Inputs to Vensim").Range("A1").Value
End Sub
Anyone have any ideas why the second sub works but the first doesn't?
Thanks, Sam.
p.s. I realise I could use copy and paste for this, was just wondering why this method didn't work in this instance.
Bookmarks