VBA Code - Delete rows once column A no longer numbers

tlc53

Active Member
Joined
Jul 26, 2018
Messages
365
Hi,

I have a set of data which is exported into excel and I would like to automatically clean it up, so that it can be analysed.

Once I select the entire data and sort it by column A, smallest to largest, it is then sorted by ticket number. I would then like to delete the rubbish on the bottom, which starts when column A is no longer a number.

For example;
Cell A12366 = 745577
Cell A12367 = 745578
Cell A12368 = #Orders
Cell A12369 = AA Insurance

So it would delete row 12368 down (in this case, down to row 16465).

Can someone please help me with this VBA code?

Thank you!
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,648
Office Version
2010
Platform
Windows
Does this macro do what you want...
Code:
Sub DeleteRubbishRows()
  Dim LastNumberRow As Long, LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  LastNumberRow = Evaluate(Replace("MAX(IF(ISNUMBER(A1:A#),ROW(A1:A#)))", "#", LastRow))
  Range(LastNumberRow + 1 & ":" & LastRow).Clear
End Sub
 

Forum statistics

Threads
1,089,337
Messages
5,407,678
Members
403,158
Latest member
Limerick2030

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top