copy data contains minus values for the last column

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hello ,
I want creating report by copy data contains minus numbers for the last column , but the macro should deal with last column that add every time and deal with change data in first sheet .

before
Bridgestone Stock Sales report (2).xls
ABCDEFGHIJKL
1DECEMBERJANUARYFEBRUARY
2SizePatternOriginArrivedSalesStockArrivedSalesStockArrivedSalesStock
3BS 175/70R13B25A32INDO---------
4BS 175/70R13EP150INDO---------
5BS 175/70R13EP150THI34420324--324-57267
6BS 175/70R13EP150TR3-3-4-1---1
7BS 185/70R13EP150INDO3420144117--17
8BS 185/70R13EP150THI-8-8---8---8
9BS 175/65R14EP150THI---------
10BS 175/65R14EP150JAP---------
11BS 175/65R14B25A32INDO---------
12BS 175/65R14B25A32THI-------150-150
13BS 175/70R14EP150THI-20-20---20---20
14BS 175/70R14MY02THI---------
15BS 185/65R14TECTHI---413-9-6
16BS 185/65R14EP150INDO9-9-18-9---9
17BS 185/65R14EP150TR---123123-13110
18BS 185/65R14150EZINDO---------
19BS 185/70R14B25A32THI---------
20BS 195/70R14150EZTHI-------100-100
In & Out Balance
Cell Formulas
RangeFormula
F3:F20F3=D3-E3
L3:L20,I3:I20I3=F3+G3-H3




result should be as this
Bridgestone Stock Sales report (2).xls
ABCD
1
2SizePatternOriginStock
3BS 175/70R13EP150TR-1
4BS 185/70R13EP150THI-8
5BS 175/65R14B25A32THI-150
6BS 175/70R14EP150THI-20
7BS 185/65R14TECTHI-6
8BS 185/65R14EP150INDO-9
9BS 195/70R14150EZTHI-100
RESULT
 
this is what I got
Microsoft Excel .xlsx
ABCD
1
2SizePatternOriginStock
3BS 175/70R13EP150TR-1
4BS 185/70R13EP150THI-8
5BS 175/65R14B25A32THI-150
6BS 175/70R14EP150THI-20
7BS 185/65R14TECTHI-6
8BS 185/65R14EP150INDO-9
9BS 195/70R14150EZTHI-100
10
RESULT
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
This will be my last reply tonight. If this doesn't give you what you want, highlight the range you want interior yellow on the RESULT sheet before you run the code.

VBA Code:
Option Explicit
Sub abdoM_V5()
    Application.ScreenUpdating = False
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("In & Out Balance")
    Set ws2 = Worksheets("RESULT")
    Dim LRow As Long, LCol As Long
    LRow = ws1.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
    LCol = ws1.Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column
    
    With ws2
        .Cells.ClearContents
        .Range("A2").Resize(, 4) = Array("Size", "Pattern", "Origin", "Stock")
        .Range("A1:D2").Interior.Color = vbYellow
    End With
    
    Dim rng As Range, r As Range
    Set rng = ws1.Range(ws1.Cells(2, 1), ws1.Cells(LRow, LCol))
    With rng
        .AutoFilter LCol, "<0"
        If ws1.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row > 2 Then
            Set rng = .Offset(1).Resize(.Rows.Count - 1)
            With rng
                Set r = Union(.Columns("A:C"), .Columns(LCol))
                r.Copy
                With ws2.Range("A3")
                    .PasteSpecial xlPasteValues
                    .PasteSpecial xlPasteFormats
                End With
                Application.CutCopyMode = False
            End With
        End If
        .AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,375
Messages
6,124,580
Members
449,174
Latest member
chandan4057

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