Put two ranges into one range from two sheets

Mussa

Active Member
Joined
Jul 12, 2021
Messages
262
Office Version
  1. 2019
  2. 2010
Hello,
I want macro to combine data for two sheets into one sheet by collection ranges.
MUSA.xlsm
ABCDE
1ITEMNAMEDEBITCREDITBALANCE
21AMUSSAN4,000.004,000.00
32ASSUMAN5,000.003,000.002,000.00
43MUSSA2,000.001,000.001,000.00
54MUSSAN3,000.003,000.00
65MUSSI1,300.00300.001,000.00
76OSMAAN1,100.001,000.00100.00
8TOTAL16,400.005,300.0011,100.00
RECEIVABLE
Cell Formulas
RangeFormula
E2:E7E2=C2-D2
C8:E8C8=SUM(C2:C7)



MUSA.xlsm
ABCDE
1ITEMNAMEDEBITCREDITBALANCE
21AMEER3,000.00-3,000.00
32AMIR300.00-300.00
43ASIIF5,000.00-5,000.00
54AZIZ12,000.00-12,000.00
65SAMMER1,100.007,000.00-5,900.00
76SANDI3,200.006,000.00-2,800.00
87SANI5,000.006,000.00-1,000.00
9TOTAL9,300.0039,300.00-21,700.00
PAYABLE
Cell Formulas
RangeFormula
E2:E8E2=C2-D2
C9:D9C9=SUM(C2:C8)
E9E9=SUM(E5:E8)


result

MUSA.xlsm
ABCDE
1ITEMNAMEDEBITCREDITBALANCE
21AMUSSAN4,000.004,000.00
33ASSUMAN5,000.003,000.002,000.00
44MUSSA2,000.001,000.001,000.00
55MUSSAN3,000.003,000.00
66MUSSI1,300.00300.001,000.00
77OSMAAN1,100.001,000.00100.00
88AMEER3,000.00-3,000.00
99AMIR300.00-300.00
1010ASIIF5,000.00-5,000.00
1111AZIZ12,000.00-12,000.00
1212SAMMER1,100.007,000.00-5,900.00
1313SANDI3,200.006,000.00-2,800.00
1414SANI5,000.006,000.00-1,000.00
15TOTAL25,700.0044,600.00-18,900.00
REPORT

thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I have assumed that the REPORT sheet already exists but no data is in it.
My code does nothing with the column A numbers in REPORT because I don't understand how you got those numbers in your sample results. Please explain.

VBA Code:
Sub CombineData()
  Sheets("RECEIVABLE").UsedRange.Copy Destination:=Sheets("REPORT").Range("A1")
  Sheets("PAYABLE").UsedRange.Offset(1).Copy Destination:=Sheets("REPORT").Range("A" & Rows.Count).End(xlUp)
  With Sheets("REPORT").UsedRange
    .Cells(.Rows.Count, 3).Resize(, 3).FormulaR1C1 = "=sum(R1C:R[-1]C)"
  End With
End Sub
 
Upvote 0
My code does nothing with the column A numbers in REPORT because I don't understand how you got those numbers in your sample results. Please explain.
my apologies !🙏
the code works greatly !(y)
the numbers should re-autonumbering 1,2,3 . should not brings from original sheets.
and I don't need showing formulas if it's possible.
 
Upvote 0
OK, try this modification.

VBA Code:
Sub CombineData_v2()
  Sheets("RECEIVABLE").UsedRange.Copy Destination:=Sheets("REPORT").Range("A1")
  Sheets("PAYABLE").UsedRange.Offset(1).Copy Destination:=Sheets("REPORT").Range("A" & Rows.Count).End(xlUp)
  With Sheets("REPORT").UsedRange
    .Cells(.Rows.Count, 3).Resize(, 3).FormulaR1C1 = "=sum(R1C:R[-1]C)"
    .Cells(2, 1).Resize(.Rows.Count - 2).Value = Evaluate("row(1:" & .Rows.Count - 2 & ")")
    .Value = .Value
  End With
End Sub
 
Upvote 0
thanks I would delete data in REPORT sheets before brings data.
the code will repeat copying to the bottom , I don't want it .
 
Upvote 0
Sorry, that is not clear to me.
Do you want the code to clear everything in REPORT before bring the data in from the other two sheets?
 
Upvote 0
Thanks for clarifying. Just one line to include

Rich (BB code):
Sub CombineData_v3()
  Sheets("REPORT").UsedRange.EntireRow.Delete
  Sheets("RECEIVABLE").UsedRange.Copy Destination:=Sheets("REPORT").Range("A1")
  Sheets("PAYABLE").UsedRange.Offset(1).Copy Destination:=Sheets("REPORT").Range("A" & Rows.Count).End(xlUp)
  With Sheets("REPORT").UsedRange
    .Cells(.Rows.Count, 3).Resize(, 3).FormulaR1C1 = "=sum(R1C:R[-1]C)"
    .Cells(2, 1).Resize(.Rows.Count - 2).Value = Evaluate("row(1:" & .Rows.Count - 2 & ")")
    .Value = .Value
  End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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