Trying to set a function as oldrows count before the delete row command is activated

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Please help to make the function count the oldrows

VBA Code:
Public Sub Delete_Or_Insert_Rows()

        Dim NewRowCount As Long
        Dim OldRowCount   As Long
        Dim LRow                As Long
        Dim rng                   As Range
        Dim ws                    As Worksheet
    
           Set ws = ActiveSheet
           LRow = Range("A1").End(xlDown).Row
           Set rng = ws.Range("A1:A" & LRow)
           OldRowCount = OldrowQty

        NewRowCount = rng.Rows.Count
        If OldRowCount > NewRowCount Then
         Exit Sub
         OldRowCount = NewRowCount
         ElseIf OldRowCount < NewRowCount Then
         Exit Sub
         ElseIf OldRowCount = NewRowCount Then
         Call Group_OrderNos
    End If
    End If
    
End Sub

Public Function OldrowQty(rng As Range) As String

        Dim OldRowCount As Long
        Dim LRow As Long
        Dim ws As Worksheet

           Set ws = ActiveSheet
           LRow = Range("A1").End(xlDown).Row
           Set rng = ws.Range("A1:A" & LRow)
           
           OldrowQty = rng.Rows.Count


End Function
 
Hi Eric,

insert anywhere in the code (keeping the same number of rows) or at the end exceeding the number of rows (meaning that you paste 5 values using only the last 3 of the data)? And I would need to know what should happen if you use ClearContents?

Ciao,
Holger
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi Eric,

insert anywhere in the code (keeping the same number of rows) or at the end exceeding the number of rows (meaning that you paste 5 values using only the last 3 of the data)? Pasting would always be at the end of the list this is when the module needs to run

And I would need to know what should happen if you use ClearContents? If you did this it would not run the code

Ciao,
Holger
 
Upvote 0
Hi Eric,

I would prefer to get some information instead of quotes from my posting. ;)

Holger
 
Upvote 0
If you used clear contents it would not run the code.

Pasting would always be at the end of the list this is when the module needs to run.
 
Upvote 0
Hi Eric,

ClearContents is triggered on my version (using 2019 with Windows11). And what should happen if the command is applied to Column A? Take your time to answer as I will take some time to re-think the problem.

Again for me to understand:
adding more entries to the list - calling procedure (running on all rows)
deleting entries, shortening list - still unsure on what to do and on what rows to work
ClearContents/paste values, keeping the number of rows - calling procedure (running an all rows)

Please correct me if I got something wrong here.

Holger
 
Upvote 0
The below shows the yellow rows need to be deleted but when you do it it can`t run the code which is what i need. Thing is when you delete rows or a row the rest of the sheet data must stays the same.
But if you paste values to the bottom it will run the code.

2022 Alton Back OrderT.xlsm
ABCDEFGHIJKLMNOPQ
13119/10/2022Goldmax LtdSO0073726NIJME6060150Ecolite D400 600x600mm Access Chamber Section x150mm High 168ISBRE002A3Underground Drainage
13219/10/2022Goldmax LtdSO0073726NIJ110TWBL110mm OD Twinwall Electrical Duct x50m; BLACK 67ISBRE002A3Underground Drainage
13319/10/2022Ground Construction LtdSO0073728LR DUCT60Naylor 600x600mm Duct Access Box 335mm Depth B125 Loading 11ISJFC001A3Underground Drainage
13419/10/2022Ground Construction LtdSO0073728LR 110TWBL110mm OD Twinwall Electrical Duct x50m; BLACK 263ISULM001ADrainage Channel
13520/10/2022Acorn Groundwork LtdSO0073638LK VFFAC60006" Clay/Plastic, 180-200mm - 160-180mm Flexible Adaptor Coupling 119ISHAR001AUnderground Drainage
13620/10/2022Independent Building Merchants Group Ltd T/A ChandlersSO0073682NIJ32WP100MDPE Water Pipe: 32mm x 100m Coil; BLUE 12.5 bar/ PE80/ SDR11 113SOJFP001ADucting
13720/10/2022M.O. Buckland & Son LtdSO0073739LR 450VCR450mm Inspection Chamber Shaft 300mm Height 1747ISULM001ADrainage Channel
13820/10/2022Harringtons Builders PlcSO0073791NIJRB100X6100mm RIDGIDUCT Twinwall x6m c/w Coupler Complies with ENATS 12-24 & BS EN 61386-24 Class 2491ISULM001ADrainage Channel
13920/10/2022Harringtons Builders PlcSO0073791NIJ8VF30200mm S/Socket Bend 30deg 30ONIA
14020/10/2022Bear Construction South LtdSO0073821LR 6VF90D160mm UPVC Drainage D/Socket Bend 87.5deg 6-1LSRAD002A1Service Pipe
14120/10/2022Independent Building Merchants Group Ltd T/A ChandlersSO0073849LR 4VF22D110mm UPVC Drainage D/Socket Bend 22.5deg 203304LSRAD002A1Service Pipe
14221/10/2022A D Bly Construction LtdSO0072558LK KVDH100.10RKompaqDrain 100mm W x 235mm D CITY PolymerChannel x1m D400 250ONIGLE001A3Underground Drainage
14321/10/2022A D Bly Construction LtdSO0072558LK CKV100KompaqDrain 100mm Galv Silt Bucket 40ONIGLE001A3Underground Drainage
14421/10/2022A D Bly Construction LtdSO0072558LK AKVDH100MF10RSKompaqDrain 100mm W x 235mm D CITY SumpAccess Unit x 1m; D400 40SOGLE001A3Underground Drainage
14521/10/2022A D Bly Construction LtdSO0072558LK AKVD100BKompaqDrain 100mm W x 260mm D Sump Basex0.5m; D400 40ONIGLE001A18/10/20223Underground Drainage
14621/10/2022Shaca Construction LtdSO0073954LKVFFDC9580-95mm Flexible Coupling 50SOVIP001A11/10/20223Flexible Fittings
14721/10/2022Statom Group LtdSO0073955LK96BTT96mm Telecoms Duct Equal Swept 90deg Jct Grey (BT Type) 15SOVIP001A11/10/20223Flexible Fittings
14821/10/2022Statom Group LtdSO0073955LK96-54BTRCBT Duct 96/54mm Reducer; Grey (BT Type Telecoms Duct) 20ISULM001ADrainage Channel
14921/10/2022Statom Group LtdSO0073960LK50PD25EDF50/60mm Polyduct x25m Coil; EDF Spec Polypipe Electric 10ISULM001ADrainage Channel
15024/10/2022HACS Construction LimitedSO0066799LK TF1023F100-400K Channel Screw 4762026ONIACO003A2Drainage Channel
15124/10/2022HACS Construction LimitedSO0066799LK T300K10CF300K 300mm W x 390mm D Blank End Cap 22ISWRE001A10/10/20223Cover & Frame
15224/10/2022HACS Construction LimitedSO0066799LK FNX300FTFMF300K 300mm D/Iron Slotted Grating x0.5m; 139182ONIESS001A11/10/20223Underground Drainage
15324/10/2022HACS Construction LimitedSO0066799LK F300K00RF300K 300mm W x 390mm D Polymer Concrete Channel x1m; F900 68114SOVIP001A14/10/20223Flexible Fittings
15424/10/2022HACS Construction LimitedSO0066799LK C300M300 Galv. Steel Bucket 38SOPLA002A11/10/20223Underground Drainage
15524/10/2022HACS Construction LimitedSO0066799LK AF300F300K 300mm W x 390mm D Sump Unit x0.5m; F900 317SOVIP001A14/10/20223Flexible Fittings
15624/10/2022Bartack LtdSO0073876LK 32WP50MDPE Water Pipe: 32mm x 50m Coil; BLUE 12.5 bar/ PE80/ SDR11 10LSDAV002A06/10/20223Drainage Channel
15724/10/2022Kuropatwa LimitedSO0073921RJ 25WP50MDPE Water Pipe: 25mm x 50m Coil; BLUE 12.5 bar/ PE80/ SDR11 211LSA04/10/20223
15825/10/2022Entex Projects LtdSO0073969NIJDUCT60Naylor 600x600mm Duct Access Box 335mm Depth B125 Loading 14104ONIWES002AService Pipe
15925/10/2022Avtar Construction LtdSO0074134LR PB160158-170mm Zinc Plated Pipe Bracket Rubber Lining - M8/M10 Thread 10018SLWRE001ACover & Frame
16025/10/2022Avtar Construction LtdSO0074134LR M10STM10 Threaded Bar x1m 125257ONIINT001AUnderground Drainage
16125/10/2022SNS Building Products LtdSO0074163NIJD3104ARECESSED SCREED Cover Galvanised: 300 x 300mm Sealed & Locked 30ISJFP001ADucting
16225/10/2022Keaney Brothers LtdSO0074174NIJ225TW90225mm ID Twinwall Duct Bend Long Radius 90deg; P/E 45ISVIP001AFlexible Fittings
16325/10/2022Shaca Construction LtdSO0074184NIJVFFSC115100-115mm Flexible Coupling VSC115 36ISMID003AAccessories
16426/10/2022MC Builders (Dorset) LtdSO0074222LR SF27/50Non-Woven GP Geotextile 2.25 x 50m Roll 122ISMID003AAccessories
16526/10/2022MC Builders (Dorset) LtdSO0074222LR 6VCE1069250mm Vision 600 Chamber Spigot End Cap c/w seal 21SLWRE001ACover & Frame
16626/10/2022MC Builders (Dorset) LtdSO0074222LR 6VCA10225250mm Vision 600 chamber, outlet adaptor to 225mm TW – Socket 236ONIINT001AUnderground Drainage
16726/10/2022Tinnelly Construction LimitedSO0074305KB VFFSC115100-115mm Flexible Coupling VSC115 36ONINAY001AUnderground Drainage
16826/10/2022DR Groundworks LtdSO0074308NIJ63TWB63mm OD Twinwall Duct x50m; BLUE 44ISNAY001ADucting
16926/10/2022DR Groundworks LtdSO0074308NIJ32WP50MDPE Water Pipe: 32mm x 50m Coil; BLUE 12.5 bar/ PE80/ SDR11 212SONAY001ADucting
17026/10/2022Statom Group LtdSO0074329LK 150RTWPY150mm Twinwall Duct x6m PERFORATED; YELLOW c/w coupler (178mm)110ISWES002AService Pipe
17127/10/2022Galamast LtdSO0074365LK 225RTWB225mm ID Twinwall Duct x6m; BLUE; P/E 10ONIRAD001ADucting
17227/10/2022O'Halloran & O'Brien LtdSO0074379LK 60PGD50PERFORATED Gas Duct: 60mm x 50m Coil; YELLOW 61SONAY001ADucting
17327/10/2022O'Halloran & O'Brien LtdSO0074379LK 110TWB110mm OD Twinwall Duct x50m; BLUE 10ONINAY001ADucting
17427/10/2022Viking Projects (UK) LtdSO0074398LR 110TWB110mm OD Twinwall Duct x50m; BLUE 10ONINAY001ADucting
17528/10/2022O'Halloran & O'Brien LtdSO0074433LK 6VCE1069250mm Vision 600 Chamber Spigot End Cap c/w seal 1721SOA
17628/10/2022O'Halloran & O'Brien LtdSO0074433LK 6VCA10225250mm Vision 600 chamber, outlet adaptor to 225mm TW – Socket 339ISA
17728/10/2022Erith Contractors LimitedSO0074450RJ VFFDC6550-65mm Flexible Coupling 15ISA
17828/10/2022McKenna Consulting LtdSO0074452GW TEUROKITCEUROKIT 100mm W x 85mm D Blank End Cap 1444ISA
17928/10/2022R Moulding & Co (Salisbury) LtdSO0074486LK JMF104QuadBox Access Chamber 915x445x150mm BT Approved 34LSA
18028/10/2022Leidon LimitedSO0074511NIJ25PTN50PURITON Barrier Pipe: 25mm x 50m Coil; Type A SDR11 16LSA
18128/10/2022Newlands Construction LtdSO0074514LK 25WP100MDPE Water Pipe: 25mm x 100m Coil; BLUE 12.5 bar/ PE80/ SDR11 10ONIA
18231/10/2022Red Hill ConstructionSO0074506LRLIB100SPolymer Concrete Sump Unit Driveway Duty c/w Galvanised A15 Grating 44SOA
Oct


Hope this makes it clear?
 
Upvote 0
Hi Eric,

how do you delete these rows: by selecting the entire row via row header, which command do you apply: shortcut CTRL&-, Delete rows from the Ribbon menu or Delete Rows from the Contextual menu (all of which fire on my system)? Or will you just work with single cells on Column A? My actual concept for building the range to further work on takes care of both of these scenarios. And the procedure to be called: on which range shall it work: the entire range, range starting with first row of change to the end or just to the end of the change?

Sorry for all the questions.

From what I see in your data and all the problems I have getting a working code: have you considered to w ork witha UserForm? You can restrict the dates in a combobox or listbox, have only the entires listed for the dates chosen, or search for a match from Column C, have only entries listed for dates who have more than one SO... from Column C on one day.... And you can start a procedure from there stating to delete an entry or add new data.

Ciao,
Holger
 
Upvote 0
Yes selecting all rows via row header. The user will highlight the row or rows then delete.
As to User Form I have plans to do this but at the minute people are on my back to get this done.
 
Upvote 0
Hi Eric,

from #24 which may be found in the opening code as well
Pasting would always be at the end of the list this is when the module needs to run.

From #26
The below shows the yellow rows need to be deleted but when you do it it can`t run the code which is what i need.

Sorry but it seems to be impossible for me to figure out what event should be catched and get the procedure to work on which rows.

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,560
Members
449,089
Latest member
Motoracer88

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