VBA for merging tables

czvrnvv

New Member
Joined
Dec 20, 2018
Messages
2
Hi, I would like to ask for some help with Excel. Im not into VBA and i have to merge 2 big tables (150X500) in a way i presented in picture below>>

Is there any easy VBA code to do it or another option how to get there?
48380405_1729942047109786_8260752175127330816_n.png
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Assuming your data is all on one sheet, then try this for results on sheet2.
The code assumes 500 rows x 150 columns.
Code:
[COLOR="Navy"]Sub[/COLOR] MG20Dec30
[COLOR="Navy"]Dim[/COLOR] Ray1 [COLOR="Navy"]As[/COLOR] Variant, Ray2 [COLOR="Navy"]As[/COLOR] Variant, Dup [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Ray1 = Range("A1").Resize(500, 150) '[COLOR="Green"][B]Change these Data ranges to suit[/B][/COLOR]
Ray2 = Range("EU1").Resize(500, 150) '[COLOR="Green"][B]Change these Data ranges to suit[/B][/COLOR]
ReDim nray(1 To UBound(Ray1, 1) + UBound(Ray2, 1), 1 To UBound(Ray1, 2))
[COLOR="Navy"]For[/COLOR] n = 1 To UBound(Ray1, 1)
    [COLOR="Navy"]For[/COLOR] Dup = 1 To 2
        c = c + 1
        [COLOR="Navy"]For[/COLOR] Ac = 1 To UBound(Ray1, 2)
            [COLOR="Navy"]If[/COLOR] Dup = 1 [COLOR="Navy"]Then[/COLOR]
                nray(c, Ac) = Ray1(n, Ac)
            [COLOR="Navy"]Else[/COLOR]
                nray(c, Ac) = Ray2(n, Ac)
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] Ac
    [COLOR="Navy"]Next[/COLOR] Dup
[COLOR="Navy"]Next[/COLOR] n
Sheets("Sheet2").Range("A1").Resize(c, 150).Value = nray
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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