I have the following code in a macro but when I run it, it only copies the value from cell B2 rather than the entire range of values from B2:D2 as I have specified in line 5 of the below code.
Sub copying()
Dim calval as variant
With worksheets("sheet1")
Set calval=.Cells(Rows.Count,"B").End(xlUp).Offset(2,3)
calval.value=Range("B2:D2").Value 'copy range of values
End With
End Sub
This is the data in cells B2:D2
21.7 21.3 22.4
Can someone please tell me how to get calval to be assigned the full range of values from B2:D2, rather than just the value in B2.
You have a few problems here. Firstly when copying to variants, they are not objects so you don’t need to use set. They also don’t have ranges as they variables. You also need to copy the value to a variant before you can set it to the output range so the order is a little off. The following code will work: