clear cells for the last two columns and exclude cells contain formulas

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
612
Office Version
  1. 2019
Hi guys
I need macro to deal with two last columns ARRIVED & SALES , should clear cells contents except formulas in TTL row and STOCK column
every time I will add new three columns ARRIVED , SALES & STOCK , so should search for headers ARRIVED , SALES in last two columns and clear cells contents except formulas .
data

TIRES REPORT.xlsm
ABCDEFGHIJKLMNOP
1
2CategorySizePatternOriginArrivedSalesStock Arrived SalesStockArrivedSalesStockArrivedSalesStock
3PSR (LRD)175/70R13B25INDO2001618405179179179
4175/70R13EP150THI00000101010
5185/70R13EP150INDO00000000
6175/65R14EP150INDO20020100303030
7175/70R14EP150THI3003000000
8175/70R14MY02THI110011005105110215110325
9185/65R14TECTHI120012000120120120
10185/65R14EP150INDO2000200223219219219
11185/65R15B250JAP00000000
12195/60R15AR20INDO11011001111121201112229
13195/60R15EP150THI2222000000
14195/60R15T001JAP000000201010201020
15195/60R15150EZTHI00000000
16195/65R15MY02THI234023400234234234
17195/65R15EP150THI444044400444444444
18195/65R15EP150JAP44044004433443344
19195/65R15T001JAP5505500555555
20195/55R16EP300THI00000000
21205/55R16RE003THI0000002525025250
22205/65R15EP150INDO00000000
23205/70R15694JAP0006606620462026
24225/75R15CT697INDO000660666666
25235/95R15CD618JAP01-100-122212243
26255/70R15CD840THI00000000
27TTL1490391451164131582291601813291602044
28PSR (HRD)215/45R17T001JAP00000000
29215/50R17EP300THI3403400343434
30215/55R17GR90INDO4404400444444
31285/30R20RE0050AJAP00000012121224
32315/35R20SPORTJAP00035035221320-7
33TTL780783501131222103122095
In & Out Balance
Cell Formulas
RangeFormula
J3,P28:P32,P3:P26,M28:M32,M3:M26,J28:J32,J8:J26,J5:J6J3=G3+H3-I3
E27:P27E27=SUM(E3:E26)
G28:G32,G3:G26G3=E3-F3
E33:P33E33=SUM(E28:E32)




result
TIRES REPORT.xlsm
ABCDEFGHIJKLMNOP
1
2CategorySizePatternOriginArrivedSalesStock Arrived SalesStockArrivedSalesStockArrivedSalesStock
3PSR (LRD)175/70R13B25INDO2001618405179179179
4175/70R13EP150THI00000101010
5185/70R13EP150INDO00000000
6175/65R14EP150INDO20020100303030
7175/70R14EP150THI3003000000
8175/70R14MY02THI110011005105110215215
9185/65R14TECTHI120012000120120120
10185/65R14EP150INDO2000200223219219219
11185/65R15B250JAP00000000
12195/60R15AR20INDO1101100111112120120
13195/60R15EP150THI2222000000
14195/60R15T001JAP00000020101010
15195/60R15150EZTHI00000000
16195/65R15MY02THI234023400234234234
17195/65R15EP150THI444044400444444444
18195/65R15EP150JAP440440044334444
19195/65R15T001JAP5505500555555
20195/55R16EP300THI00000000
21205/55R16RE003THI000000252500
22205/65R15EP150INDO00000000
23205/70R15694JAP00066066204646
24225/75R15CT697INDO000660666666
25235/95R15CD618JAP01-100-1222121
26255/70R15CD840THI00000000
27TTL1490391451164131582291601813001813
28PSR (HRD)215/45R17T001JAP00000000
29215/50R17EP300THI3403400343434
30215/55R17GR90INDO4404400444444
31285/30R20RE0050AJAP000000121212
32315/35R20SPORTJAP00035035221313
33TTL78078350113122210300103
In & Out Balance
Cell Formulas
RangeFormula
J3,P28:P32,P3:P26,M28:M32,M3:M26,J28:J32,J8:J26,J5:J6J3=G3+H3-I3
E27:P27E27=SUM(E3:E26)
G28:G32,G3:G26G3=E3-F3
E33:P33E33=SUM(E28:E32)
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi Abdo, try this:
VBA Code:
Sub Clear_Last_Two()
    Dim ws As Worksheet, LCol As Long, LRow As Long
    Set ws = Worksheets("In & Out Balance")
    LCol = ws.Rows("2:2").Find("*", , xlFormulas, , 2, 2).Column - 2
    LRow = ws.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
    
    On Error Resume Next
    ws.Range(ws.Cells(3, LCol), ws.Cells(LRow, LCol + 1)).SpecialCells(xlCellTypeConstants).ClearContents
    Err.Clear
End Sub
 
Upvote 0
Solution
Excellent !
just question , what does it mean "*" in some lines?
thanks very much for your solution . (y)
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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