Transfer data from one range to another using array

trux101

New Member
Joined
Feb 10, 2016
Messages
19
Hi, can anyone spot the error in my ways on this? I've been on it for hours!

Essentially looking to copy data from Raw Data to Table5 which is on a separate sheet - but without using copy and paste that is taking way too long for my 20,000 rows and 85 columns of data. Any help will be greatly appreciated!

Public Sub Copy_3()

Dim DestRng As Variant, Virt As Variant

With Worksheets("Raw Data")
Set LastData = .Cells(.Rows.Count, "A").End(xlUp)
LastLine = LastData.Row
End With

Virt = Worksheets("Raw Data").Range("A2:N" & LastLine)
DestRng = Worksheets("Test").Range("Table5")

DestRng = Virt
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I think I understand what you are describing, although I've never attempted it with a table range. Your code here might not be working for a couple reasons.

Code:
[COLOR=#333333]Virt = Worksheets("Raw Data").Range("A2:N" & LastLine)[/COLOR]
[COLOR=#333333]DestRng = Worksheets("Test").Range("Table5")[/COLOR]
here, when making a vairable = to an object, in this case a range, you must use set

Code:
set [COLOR=#333333]Virt = Worksheets("Raw Data").Range("A2:N" & LastLine)[/COLOR]
[COLOR=#333333]set DestRng = Worksheets("Test").Range("Table5")[/COLOR]

For making one ranges valus = another's with without using copy/paste i've used this syntax (which assumes ranges are the exact same size -- so no idea how a table would work):
Code:
[COLOR=#333333]Worksheets("Test").Range("A2:N" & LastLine).value = [/COLOR][COLOR=#333333]Worksheets("Raw Data").Range("A2:N" & LastLine).value[/COLOR]
note the .value
 
Last edited:
Upvote 0
You'll need to make the destination range the same size as Virt to accommodate all the values. Here's one way you could do this:

Code:
With Worksheets("Raw Data")
    Virt = .Range("A2:N" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value
End With

Worksheets("Test").Range("Table5").Resize(UBound(Virt), UBound(Virt, 2)).Value = Virt
 
Upvote 0
Re: Transfer data from one range to another using array [SOLVED]

Thank you StephenCrump, ODIN! It's worked. For anyone ever looking:
Public Sub Copy()
Dim Virt As Variant

With Worksheets("Raw Data")
Set LastData = .Cells(.Rows.Count, "A").End(xlUp)
LastLine = LastData.Row
Virt = .Range("A2:N" & .Cells(.Rows.Count, "A").End(xlUp).Row).value
End With

Worksheets("Test").Range("Table5").Resize(UBound(Virt), UBound(Virt, 2)).value = Virt
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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