move and delete rows contains minus and positive value from range to another

Mussa

Active Member
Joined
Jul 12, 2021
Messages
262
Office Version
  1. 2019
  2. 2010
Hi,
I would macro to deal with about 1000 names for each range into two sheets.
in RECEIVABLE sheet when contains minus value in BALANCE column then will delete it and brings rows contains positive values in BALANCE column from PAYPAL sheet and recalculate as in BALANCE column and in TOTAL row.
as to PAYPAL sheet when contains positive value in BALANCE column then will delete it and brings rows contains minus values in BALANCE column from RECEIVABLE sheet and recalculate as in BALANCE column and in TOTAL row. Also should delete row contains zero in BALANCE column for both sheets.
MUSA1.xlsm
ABCDE
1ITEMNAMEDEBITCREDITBALANCE
21AMUSSAN4,000.004,000.00
32ANISAMAN3,000.003,000.000.00
43ASSUMAN5,000.006,000.00-1,000.00
54MUSSA2,000.001,000.001,000.00
65MUSSAN3,000.003,000.00
76MUSSI1,300.006,000.00-4,700.00
87OSMAAN1,100.005,000.00-3,900.00
9TOTAL19,400.0021,000.00-1,600.00
RECEIVABLE
Cell Formulas
RangeFormula
E2:E8E2=C2-D2
C9:E9C9=SUM(C2:C8)



MUSA1.xlsm
ABCDE
1ITEMNAMEDEBITCREDITBALANCE
21AMEER7,000.003,000.004,000.00
32AMIR300.00-300.00
43ASIIF6,000.005,000.001,000.00
54AZIZ12,000.00-12,000.00
65SAFAR8,000.002,000.006,000.00
76SAMMER1,100.007,000.00-5,900.00
87SANDI7,000.006,000.001,000.00
98SANI15,000.006,000.009,000.00
10TOTAL44,100.0041,300.002,800.00
PAYABLE
Cell Formulas
RangeFormula
E2:E9E2=C2-D2
C10:E10C10=SUM(C2:C9)



result
MUSA1.xlsm
ABCDE
1ITEMNAMEDEBITCREDITBALANCE
21AMEER7,000.003,000.004,000.00
32AMUSSAN4,000.004,000.00
43ASIIF6,000.005,000.001,000.00
54MUSSA2,000.001,000.001,000.00
65MUSSAN3,000.003,000.00
76SAFAR8,000.002,000.006,000.00
87SANDI7,000.006,000.001,000.00
98SANI15,000.006,000.009,000.00
10TOTAL52,000.0023,000.0029,000.00
RECEIVABLE
Cell Formulas
RangeFormula
E2:E9E2=C2-D2
C10:E10C10=SUM(C2:C9)



MUSA1.xlsm
ABCDE
1ITEMNAMEDEBITCREDITBALANCE
21AMIR300.00-300.00
32ASSUMAN5,000.006,000.00-1,000.00
43AZIZ12,000.00-12,000.00
54MUSSI1,300.006,000.00-4,700.00
65OSMAAN1,100.005,000.00-3,900.00
76SAMMER1,100.007,000.00-5,900.00
8TOTAL8,500.0036,300.00-27,800.00
PAYABLE
Cell Formulas
RangeFormula
E2:E7E2=C2-D2
C8:E8C8=SUM(C2:C7)

every time I will add new data and change every time for both sheets.
last thing if there is way to get rid of the formulas.
thanks in advanced.
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
Sub test()
    Dim s$(1), e, ws As Worksheet
    s(1) = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & _
        ";Extended Properties='Excel 12.0;HDR=Tes';"
    s(0) = "Select * From `RECEIVABLE$` Where `Name` Is Not Null " & _
        "Union Select * From `PAYABLE$` Where `Name` Is Not Null;"
    With CreateObject("ADODB.Recordset")
        .Open s(0), s(1), 3, 3, 1
        For Each e In Array(Array("receivable", ">"), Array("payable", "<"))
            Set ws = Sheets(e(0))
            .Filter = ""
            .Filter = "[BALANCE]" & e(1) & "0"
            ws.[a1].CurrentRegion.Offset(1).ClearContents
            ws.[a2].CopyFromRecordset .DataSource
            With ws.[a1].CurrentRegion
                .Offset(1).Columns(1) = Evaluate("row(1:" & .Rows.Count & ")")
                .Rows(.Rows.Count + 1).Cells(1) = "TOTAL"
                .Rows(.Rows.Count + 1).Range("c1:e1").FormulaR1C1 = "=sum(r2c:r[-1]c)"
            End With
        Next
    End With
End Sub
 
Upvote 0
Awesome !
may you fix the formatting and borders when increase data will leave the color and borders for TOTA word in last row and will not show the borders . so should delete the color left in TOTAL word and highlight for new location for TOTAL word when move to the bottom and create borders , and if decrease data by move to above then delete the color left in TOTAL word , borders and highlight for new location for TOTAL word when move to the above .
thanks
 
Upvote 0
Code:
Sub test()
    Dim s$(1), e, ws As Worksheet
    s(1) = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & _
        ";Extended Properties='Excel 12.0;HDR=Tes';"
    s(0) = "Select * From `RECEIVABLE$` Where `Name` Is Not Null " & _
        "Union Select * From `PAYABLE$` Where `Name` Is Not Null;"
    With CreateObject("ADODB.Recordset")
        .Open s(0), s(1), 3, 3, 1
        For Each e In Array(Array("receivable", ">"), Array("payable", "<"))
            Set ws = Sheets(e(0))
            With ws.[a1].CurrentRegion.Offset(1)
                .Borders.LineStyle = xlNone
                .Interior.ColorIndex = xlNone
                .Font.Bold = False
                .ClearContents
            End With
            .Filter = ""
            .Filter = "[BALANCE]" & e(1) & "0"
            ws.[a2].CopyFromRecordset .DataSource
            With ws.[a1].CurrentRegion
                .Offset(1).Columns(1) = Evaluate("row(1:" & .Rows.Count & ")")
                With .Rows(.Rows.Count + 1)
                    .Cells(1) = "TOTAL"
                    .Cells(1).Font.Bold = True
                    .Cells(1).Interior.Color = .Parent.Range("a1").Interior.Color
                    .Range("c1:e1").FormulaR1C1 = "=sum(r2c:r[-1]c)"
                End With
            End With
        Next
    End With
End Sub
 
Upvote 0
Solution
You misunderstood me.
should delete formatting and borders for there is no data in some rows .
 
Upvote 0
Then I don't understand what you talking about.
Good luck.
 
Upvote 0
Maybe the pictures help you
this is what I got based on the first code
P1.PNG



P2.PNG



what I want

P3.PNG


P4.PNG
 
Upvote 0
The code I post in #4 should do it, just missing new borders.
Rich (BB code):
                End With
                .Resize(.Rows.Count + 1).Borders.Weight = 2   '<--- add this line
            End With
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,189
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