Array referencing to another worksheet

Inactiver183192

New Member
Joined
Jun 12, 2011
Messages
15
Hi I'm just trying to copy an array from worksheet inputs that so many rows down and then copy it to the worksheet "data" however my second line doesn't work. What would be wrong with this?

Also i then want to copy the array into Cell (9,4) or D9 but transpose my vArray. is there a quick way or should I just go the pastespecial transpose way?

Thanks all!


[CODE
Dim Last As Long
Dim vArray()

LastRow = Worksheets("Inputs").Range("C2").End(xlDown).Row
vArray = Worksheets("Inputs").Range(Cells(2, 3), Cells(LastRow, 3)).Value
Worksheets("Data").Range(Cells(9, 4), Cells(9, LastRow)).Value = vArray

[/CODE]
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this:

Code:
Sub Macro2()

    With Sheets("Inputs")
        LastRow = .[c65000].End(xlUp).Row
        .Range(.Cells(2, 3), .Cells(LastRow, 3)).Copy
    End With
    Sheets("Data").Range("G9").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True

    Application.CutCopyMode = False
    
End Sub
 
Upvote 0
Hi Roli! Thanks for the help I'll try that out. Just another question why is it that this works

Code:
Worksheets("Spot").Range("A2:P10").Value = Worksheets("Data").Range(Cells(9, 2), Cells(LastRow, LastCol)).Value

BUT not this

Code:
Worksheets("Spot").Range(Cells(9, 2), Cells(LastRow, LastCol)).Value = Worksheets("Data").Range(Cells(9, 2), Cells(LastRow, LastCol)).Value

If LastRow = 19 and last col =9
They should be referring to the same area? Thanks!
 
Upvote 0
The formula

Code:
Worksheets("Spot").Range(Cells(9, 2), Cells(LastRow, LastCol)).Value = Worksheets("Data").Range(Cells(9, 2), Cells(LastRow, LastCol)).Value
will not work as the above VBA code does not precicely indicate where the cells are.

To make the above formula work use the following:

Code:
Worksheets("Spot").Range(Worksheets("Spot").Cells(9, 2), Worksheets("Spot").Cells(LastRow, LastCol)).Value = Worksheets("Data").Range(Worksheets("Data").Cells(9, 2), Worksheets("Data").Cells(LastRow, LastCol)).Value

or

Code:
Set wsSp = worksheets("Spot")
Set wsDa = worksheets("Data")

     wsSp.Range(wsSp.Cells(9, 2), wsSp.Cells(LastRow, LastCol)).Value = wsDa.Range(wsDa.Cells(9, 2), wsDa.Cells(LastRow, LastCol)).Value
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,310
Members
452,906
Latest member
phanmemchatdakenhupviral

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top