get 2 ranges form 2 sheets into one array

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,794
Office Version
  1. 2013
Platform
  1. Windows
hi all;
please can any body help me with this:
I'm trying to assign 2 ranges in e sheets into one array

Dim myData() As Variant, Temp As Variant
Dim Obj As Object, I, x, lr As Long
Dim lr1, lr2 As Long
Sheet1.Activate
lr1 = Cells(Rows.Count, 1).End(xlUp).Row
ReDim myData(0 To lr1)
Sheet2.Activate
lr2 = Cells(Rows.Count, 1).End(xlUp).Row

myData = Sheet1.Range("A2:A" & lr1).Value
ReDim Preserve myData(LBound(myData) To LBound(myData), UBound(myData) + 1 To lr1+lr2)

For x = lr1 + 1 To UBound(myData)
myData(x) = Sheet2.Range("A" & x)
Next x

I had reached this far but line in red big problem I could not over come it
any help please
Thanks
 
Here's an example you can adapt. In this case the two ranges are in col A and col B and the combined array is written to col C.
Code:
Sub TwoArraysToOne()
Dim V1 As Variant, V2 As Variant, Vout As Variant, ct As Long
V1 = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Value
V2 = Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row).Value
ReDim Vout(1 To UBound(V1, 1) + UBound(V2, 1), 1 To 1)
For i = LBound(V1, 1) To UBound(V1, 1)
       ct = ct + 1
       Vout(ct, 1) = V1(i, 1)
Next i
For i = LBound(V2, 1) To UBound(V2, 1)
       ct = ct + 1
       Vout(ct, 1) = V2(i, 1)
Next i
Range("C1:C" & ct).Value = Vout
End Sub
 
Upvote 0
Solution
thank you mr. joe
let me check and come back to you
great help
 
Upvote 0
thank you mr. joe
let me check and come back to you
great help
Hi Joe;
well done
now I'll try to get the unique values from the Vout array
may I come back to you If I failed?
Thank you very much
 
Last edited:
Upvote 0

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