ignore zero value when copy the firs three column & the last three columns

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hello
I got this code from Peter_Ss he helped me in previous thread
VBA Code:
Sub Copy_Columns()
  Sheets("output").UsedRange.EntireColumn.Delete
  With Sheets("In & Out Balance")
    Intersect(.UsedRange, Union(.Columns("B:D"), .Columns(.Cells(2, Columns.Count).End(xlToLeft).Column - 2).Resize(, 3))).Copy
  End With
  With Sheets("output")
    .Range("A1").PasteSpecial Paste:=xlPasteValues
    .Range("A1").PasteSpecial Paste:=xlPasteFormats
    .Columns("E:G").NumberFormat = "#,##0.00"
    .UsedRange.Columns.AutoFit
  End With
End Sub
based on the code will copy columns (B,C,D) and the last three columns based on headers (ARRIVES,SALES,STOCK) which locates under the month
the last three columns will issued every month . so when copy it depends on headers (ARRIVES,SALES,STOCK) which locates under the month
now what I want when copy the last three columns (ARRIVES,SALES,STOCK) should just contain values one of two columns (ARRIVES,SALES) I mean if they're two both contain value 0 then should not copy data columns (B,C,D) & last three columns (ARRIVES,SALES,STOCK)
just copy columns (B,C,D) & last three columns (ARRIVES,SALES,STOCK) if one of two columns (ARRIVES,SALES) don't contain 0 . but this condition should not apply in row contains TTL as in column B
last thing the data in row will increase for 2300 rows and the columns will increase for 50 columns .
any idea to update code or alternitave please?

before
(5).xlsx
ABCDEFGHIJKLM
1OctNovDec
2CategorySizePatternOriginArrivedSalesStock Arrived SalesStock Arrived SalesStock
3PSR (LRD)175/70R13B25INDO20016184517911190
4175/70R13EP150THI-----10--10
5185/70R13EP150INDO-------1-1
6175/65R14EP150INDO20-2010-30111031
7175/70R14EP150THI30-30------
8175/70R14MY02THI110-110-5105--105
9185/65R14TECTHI120-120--120--120
10185/65R14EP150INDO200-20022321933-252
11 185/65R14150EZINDO---33-33--33
12185/65R15TC10INDO---33-33--33
13185/65R15T005INDO---45-45--45
14185/65R15T01JAP221210--10--10
15185/65R15B250JAP---------
16195/60R15AR20INDO11-11--11--11
17195/60R15EP150THI2222----123-123
18195/60R15T001JAP---------
19 195/60R15150EZTHI---------
20195/65R15MY02THI234-234--234--234
21195/65R15EP150THI444-444--444--444
22195/65R15EP150JAP44-44--44--44
23195/65R15T001JAP55-55--555-60
24195/55R16EP300THI---------
25205/55R16 RE003THI---------
26205/65R15EP150INDO------5-5
27205/65R15MY02THI---5-55-10
28205/65R15T01JAP---------
29FS 205/65R15TZ700JAP---------
30215/65R15T005 INDO---5-5555
31205/70R15694JAP---66-66--66
32225/75R15CT697INDO---66-66--66
33235/95R15CD618JAP-1-1---11--
34255/70R15CD840THI---------
35205R16C D840THI---------
36205/R16CD697THI---------
37205/55R16AR20INDO---------
38205/55R16G3JAP---------
39205/55R16T001---------
40205/55R16ER300POL---------
41205/60R16AR20INDO---------
42205/60R16T005THI---------
43205/60R16T001JAP---------
44205/65R16EP300INDO---------
45 205/65R16EP30ZINDO---------
46265/70R16D840THI---------
47275/70R16H005THI---------
48275/70R16D694JAP---------
49LT285/75R16AT001JAP---------
50TTL1512511461285131713199161896
51PSR (HRD)215/45R17T001JAP---------
52215/50R17EP300THI34-34--34--34
53215/55R17GR90INDO44-44--44--44
54215/55R17T001JAP---------
55215/55R17T005JAP---------
56275/55R20ALENZAJAP-----121-13
57285/50R20DSPORT------1-1
58275/65R18116HTHI-------1-1
59275/65R18AL01JAP22-2222-4412-56
60285/60R18T01JAP22-22--22--22
61285/60R18D850JAP22-221-231-24
62245/40R20RE050JAP---------
63265/50R20SPORTJAP---------
64275/30R20RE050JAP---------
65275/40R20DHPJAP---------
66275/55R20D680JAP---------
67285/30R20RE0050AJAP---------
68315/35R20SPORTJAP---------
69TTL144-14423-179151193
In & Out Balance
Cell Formulas
RangeFormula
J3,M51:M68,M3:M49,J57:J68,J51:J55,J8:J49,J5:J6J3=G3+H3-I3
E50:M50E50=SUM(E3:E49)
G51:G68,G3:G49G3=E3-F3
E69:M69E69=SUM(E51:E68)

my data are 2000 rows and will increase overtime
after
(5).xlsx
ABCDEFG
1ITEMSizePatternOrigin Arrived SalesStock
21175/70R13B25INDO11190
32185/70R13EP150INDO-1-1
43175/65R14EP150INDO111031
54185/65R14EP150INDO33-252
65195/60R15EP150THI123-123
76195/65R15T001JAP5-60
87205/65R15EP150INDO5-5
98205/65R15MY02THI5-10
109215/65R15T005 INDO555
11TTL19816675
121275/55R20ALENZAJAP1-13
132285/50R20DSPORT1-1
143275/65R18116HTHI-1-1
154275/65R18AL01JAP12-56
165285/60R18D850JAP1-24
17TTL15193
output
Cell Formulas
RangeFormula
E11:G11E11=SUM(E2:E10)
E17:G17E17=SUM(E12:E16)
 
Last edited by a moderator:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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