Autonumbering in cell based on last row in column

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
573
Office Version
  1. 2019
Hello,
I would autonumbering in E13 cell after INVOICE NO: when I sum the whole column C in last row
should show BSJ & QTY total and "-" and increment number after Hyphen .
I would increase numbering when click button and decreasing number when click another button
the buttons are not Active X
the data before
فاتورة 174305.xlsm
ABCDE
13PR_00001INVOIECE NO :
14
15
16
17
18
19
20
21
22
23ITEMBRANDQTYPRICETOTAL
241MOTORMECH 150A L KOR2.001,000.002,000.00
252NOVA 200A L KOR2.001,500.003,000.00
263VEGA 55A L KOR1.00400.00400.00
274XPRO 70A L KOR4.00540.002,160.00
285XPRO 70A R KOR4.00540.002,160.00
296BATTREY 30A CHI1.00275.00275.00
307BOHANO 55A L JAP1.00370.00370.00
318KM 215/65R16 TA21 KOR5.00435.002,175.00
329KM 195/65R15 TA21 KOR4.00350.001,400.00
3310XPRO 150A L KOR2.001,000.002,000.00
3411XPRO 100A L KOR1.00625.00625.00
3512DUNLOP 285/60R18 AT25 JAP1.001,110.001,110.00
3613APPLLO 265/65R17 INDIA4.00595.002,380.00
3714BS 1400R20 R180 JAP2.004,500.009,000.00
3815XPRO 200A L KOR4.001,285.005,140.00
3916XPRO 150A L KOR4.001,000.004,000.00
4017XPRO 100A R KOR10.00610.006,100.00
4118XPRO 100A L KOR10.00620.006,200.00
4219XPRO 70A R KOR15.00510.007,650.00
4320XPRO 70A L KOR10.00515.005,150.00
4421XPRO 60A L KOR15.00425.006,375.00
4522XPRO 55A L KOR10.00390.003,900.00
4623YOKOHAMA 7A MALAYSIA 1.00265.00265.00
4724XPRO 80A L KPOR1.00570.00570.00
4825HANKOOK 215/60R17 KOR4.00525.002,100.00
4926335/80R20 CHI4.003,125.0012,500.00
5027XPRO 70A R KOR5.00540.002,700.00
5128ASIMCO 70A R KOR9.00540.004,860.00
5229FORTEN 235/60R18 XL THI4.00445.001,780.00
5330TOP TRUST 6.00-16 8PR F2-1 TT CHI2.00365.00730.00
5431PROLITE 74A R KOR1.00565.00565.00
5532HANKOOK 235/60R17 K406 KOR5.00540.002,700.00
5633KM 155R13C KC55 KOR4.00415.001,660.00
5734KM 195R15C KC53 VIT2.00440.00880.00
5835CRYSTAL 150A KOR10.001,000.0010,000.00
5936XPRO 150A L KOR2.001,000.002,000.00
6037XPRO 70A L KOR2.00505.001,010.00
6138VEGA 70A L KOR10.00505.005,050.00
6239DUNLOP 285/60R18 AT25 JAP5.001,125.005,625.00
6340PRINX 235/70R16 HH2 THI4.00475.001,900.00
6441BS 265/65R17 D693 THI 4.00895.003,580.00
6542HANKOOK 215/70R16C KOR4.00490.001,960.00
6643XPRO 70A R KOR2.00515.001,030.00
6744PROLITE 44A L KOR1.00365.00365.00
6845XPRO 74A L KOR1.00515.00515.00
6946XPRO 70A L KOR1.00505.00505.00
7047XPRO 90A L KOR1.00600.00600.00
7148YOKOHAMA 205/65R16 ES32 JAP4.00455.001,820.00
7249DUNLOP 265/70R18 AT23 JAP4.001,100.004,400.00
7350LASSA 4*4 235/70R16 A/T2 TR4.00575.002,300.00
7451LASSA 235/50R19 H/P2 TR4.00560.002,240.00
7552DUNLOP 285/65R17 JAP2.00950.001,900.00
7653VEGA 70A R KOR5.00500.002,500.00
7754XPRO 90A L KOR9.00605.005,445.00
7855XPRO 80A L KPOR1.00570.00570.00
7956KM 285/75R16 MT51 VIT8.00835.006,680.00
8057XPRO 60A L KOR2.00425.00850.00
8158KM 245/70R17 AT52 VIT4.00645.002,580.00
8259TIRES 245/50R19 DFG CHI4.001,000.004,000.00
83TOTAL252.00174,305.00
SH1
Cell Formulas
RangeFormula
C83,E83C83=SUM(C24:C82)
E24:E82E24=C24*D24


result
فاتورة 174305.xlsm
ABCDE
12PR_00001فاتورة رقم
13PR_00001INVOIECE NO : BSJ252-1
14
15
16
17
18
19
20
21
22
23ITEMBRANDQTYPRICETOTAL
241MOTORMECH 150A L KOR2.001,000.002,000.00
252NOVA 200A L KOR2.001,500.003,000.00
263VEGA 55A L KOR1.00400.00400.00
274XPRO 70A L KOR4.00540.002,160.00
285XPRO 70A R KOR4.00540.002,160.00
296BATTREY 30A CHI1.00275.00275.00
307BOHANO 55A L JAP1.00370.00370.00
318KM 215/65R16 TA21 KOR5.00435.002,175.00
329KM 195/65R15 TA21 KOR4.00350.001,400.00
3310XPRO 150A L KOR2.001,000.002,000.00
3411XPRO 100A L KOR1.00625.00625.00
3512DUNLOP 285/60R18 AT25 JAP1.001,110.001,110.00
3613APPLLO 265/65R17 INDIA4.00595.002,380.00
3714BS 1400R20 R180 JAP2.004,500.009,000.00
3815XPRO 200A L KOR4.001,285.005,140.00
3916XPRO 150A L KOR4.001,000.004,000.00
4017XPRO 100A R KOR10.00610.006,100.00
4118XPRO 100A L KOR10.00620.006,200.00
4219XPRO 70A R KOR15.00510.007,650.00
4320XPRO 70A L KOR10.00515.005,150.00
4421XPRO 60A L KOR15.00425.006,375.00
4522XPRO 55A L KOR10.00390.003,900.00
4623YOKOHAMA 7A MALAYSIA 1.00265.00265.00
4724XPRO 80A L KPOR1.00570.00570.00
4825HANKOOK 215/60R17 KOR4.00525.002,100.00
4926335/80R20 CHI4.003,125.0012,500.00
5027XPRO 70A R KOR5.00540.002,700.00
5128ASIMCO 70A R KOR9.00540.004,860.00
5229FORTEN 235/60R18 XL THI4.00445.001,780.00
5330TOP TRUST 6.00-16 8PR F2-1 TT CHI2.00365.00730.00
5431PROLITE 74A R KOR1.00565.00565.00
5532HANKOOK 235/60R17 K406 KOR5.00540.002,700.00
5633KM 155R13C KC55 KOR4.00415.001,660.00
5734KM 195R15C KC53 VIT2.00440.00880.00
5835CRYSTAL 150A KOR10.001,000.0010,000.00
5936XPRO 150A L KOR2.001,000.002,000.00
6037XPRO 70A L KOR2.00505.001,010.00
6138VEGA 70A L KOR10.00505.005,050.00
6239DUNLOP 285/60R18 AT25 JAP5.001,125.005,625.00
6340PRINX 235/70R16 HH2 THI4.00475.001,900.00
6441BS 265/65R17 D693 THI 4.00895.003,580.00
6542HANKOOK 215/70R16C KOR4.00490.001,960.00
6643XPRO 70A R KOR2.00515.001,030.00
6744PROLITE 44A L KOR1.00365.00365.00
6845XPRO 74A L KOR1.00515.00515.00
6946XPRO 70A L KOR1.00505.00505.00
7047XPRO 90A L KOR1.00600.00600.00
7148YOKOHAMA 205/65R16 ES32 JAP4.00455.001,820.00
7249DUNLOP 265/70R18 AT23 JAP4.001,100.004,400.00
7350LASSA 4*4 235/70R16 A/T2 TR4.00575.002,300.00
7451LASSA 235/50R19 H/P2 TR4.00560.002,240.00
7552DUNLOP 285/65R17 JAP2.00950.001,900.00
7653VEGA 70A R KOR5.00500.002,500.00
7754XPRO 90A L KOR9.00605.005,445.00
7855XPRO 80A L KPOR1.00570.00570.00
7956KM 285/75R16 MT51 VIT8.00835.006,680.00
8057XPRO 60A L KOR2.00425.00850.00
8158KM 245/70R17 AT52 VIT4.00645.002,580.00
8259TIRES 245/50R19 DFG CHI4.001,000.004,000.00
83TOTAL252.00174,305.00
SH1
Cell Formulas
RangeFormula
C83,E83C83=SUM(C24:C82)
E24:E82E24=C24*D24


the first time will be BSJ252-1 when click button to increase number , but if I click another button to decrease then will not decrease
next time when increase will be BSJ252-2 and if I decrease then will be BSJ252-1.
thanks in advanced.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Create 2 buttons. One for increase other for decrease
1730479680599.png

For the increase button you put the following code:
VBA Code:
Sub increaseNum()
  Call in_de("+")
End Sub

For the decrease button you put the following code:
VBA Code:
Sub decreaseNum()
  Call in_de("-")
End Sub

In the same module put the following code:
VBA Code:
Sub in_de(op As String)
  Dim c As Range
  Dim lr As Long
  Dim tot As Double
  Dim s1 As String, s2 As String
  
  Const px1 = "INVOICE NO : "
  Const px2 = "BSJ"
  Set c = Range("E13")
  
  lr = Range("A" & Rows.Count).End(3).Row
  If Range("A" & lr).Value = "TOTAL" Then
    tot = Range("C" & lr).Value
    If c.Value = "" Or Left(c.Value, Len(px1)) <> px1 Or InStr(1, c.Value, "-") = 0 Then
      c.Value = px1 & px2 & tot & "-1"
    Else
      s1 = Split(c.Value, "-")(0)
      s2 = Val(Split(c.Value, "-")(1))
      If op = "+" Then
        s2 = s2 + 1
      Else
        If s2 - 1 > 0 Then s2 = s2 - 1
      End If
      c.Value = px1 & px2 & tot & "-" & s2
    End If
  Else
    MsgBox "TOTAL does not exists"
  End If
End Sub

Try and comment.

🤗
 
Upvote 0
Solution

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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