vba - Can we merge two array using redim preserve

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

How to merge two array Data into Single Array using Redim Preserve and paste in Range("I1")

I have below data Range("A1").currentregion and Range("E1").currentregion
I want Output in Column I1.


aaaaaaaaabbbbbbbbbaaaaaaaaa
aaaaaaaaabbbbbbbbbaaaaaaaaa
aaaaaaaaabbbbbbbbbaaaaaaaaa
aaaaaaaaabbbbbbbbbaaaaaaaaa
bbbbbbbbb
bbbbbbbbb
bbbbbbbbb
bbbbbbbbb


VBA Code:
Option Explicit
Sub MergeTwoArray()

    Dim ar1() As Variant
    Dim ar2() As Variant
    
    ar1 = Range("A1").CurrentRegion.Value
    ar2 = Range("e1").CurrentRegion.Value
    
    Dim rows As Long: Dim columns As Long
    
    rows = UBound(ar1, 1)
    columns = UBound(ar1, 2)
    
    ReDim Preserve ar1(500)  'Getting subscript out of range I cant increase existing size.
    Range("I1").Resize(rows, columns).Value = ar1  'Single Array I can paste using this line.
            
End Sub


Thanks
mg
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You don't really need to merge them.
VBA Code:
    Dim ar1() As Variant
    Dim ar2() As Variant
    
    ar1 = Range("A1").CurrentRegion.Value
    ar2 = Range("e1").CurrentRegion.Value
    
    Range("I1").Resize(UBound(ar1, 1), UBound(ar1, 2)).Value = ar1
    Range("I1").Offset(UBound(ar1, 1)).Resize(UBound(ar2, 1), UBound(ar2, 2)).Value = ar2
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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