Put two ranges into one range from two sheets

Mussa

Active Member
Joined
Jul 12, 2021
Messages
264
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
 
Hi peter
I'm not sure why problem shows in formatting despite of this line is existed
VBA Code:
  Sheets("REPORT").UsedRange.EntireRow.Delete
this is what I got.
fr.JPG

I look forward as in result in OP !
I hope to hear from you soon.
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I look forward as in result in OP !
I hope to hear from you soon.
Your reply in post 9 and marking post 8 as the solution implies that the code worked for you back then. It still does for me using the post 1 sample data.
What has changed since then? (Look carefully in 'PAYABLE' in the row below the TOTAL row. Could there be something somewhere in that row?)

If your raw data has changed, please post 'RECEIVABLE' and 'PAYABLE' again with XL2BB
If you have changed the post 8 code in any way then please post the current code that you are using.
 
Last edited:
Upvote 0
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)




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
87AMEER3,000.00-3,000.00
98AMIR300.00-300.00
109ASIIF5,000.00-5,000.00
1110AZIZ12,000.00########
1211SAMMER1,100.007,000.00-5,900.00
1312SANDI3,200.006,000.00-2,800.00
1413SANI5,000.006,000.00-1,000.00
15149,300.0039,300.00########
163500083900-40600
REPORT

by the way after maintenance for forum in previous time XL2BB tool doesn't show colors for cells as I provide you the picture.



VBA 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
by the way after maintenance for forum in previous time XL2BB tool doesn't show colors for cells as I provide you the picture.
I don't think it is anything to do with forum maintenance. In post 1 you were using XL2BB version ..
1732278648236.png


Now you are using an older version ..
1732278680250.png




(Look carefully in 'PAYABLE' in the row below the TOTAL row. Could there be something somewhere in that row?)
Did you do that?
Run this code and report what the message box returns.
VBA Code:
Sub Check()
  MsgBox Sheets("PAYABLE").UsedRange.Rows.Count
End Sub
 
Upvote 0
Run this code and report what the message box returns.
gives 9
problem seems from the file . I create new workbook and works .
sorry buddy for waste your time .🙏
everything is ok.:)
 
Upvote 0
Glad you have it sorted. Thanks for letting us know. (y)
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
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