Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    delete rows that do not start with a number

    Im trying to format some information from a pdf. I'll paste everything into excel, delete the rows I dont need then format the text strings to be suitable for a table.




    I want to keep only the lines that start with a number, all other rows can be deleted. This is the code im working on:

    Code:
    Sub test()
      
        Dim Ncell As Range
        Dim IsNotNumber As Boolean
         
        For Each Ncell In Rangeleft("a" & Rows.Count).End(xlUp)
            If Not IsNumeric(Ncell) Then Rows(Ncell).Delete
               
            
        Next Ncell
         
      
    End Sub

    I had this working to an extent i just need this to all work as one: (obviously this is deleting the lines WITH numbers. I was just testing with it.

    Code:
    If IsNumeric(left(Range("a" & i).Value, 1)) Then Rows(i).Delete
    All help appreciated, Thanks

    Andy

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If you want to delete the rows that do not start with a number, then change this:
    Code:
    If IsNumeric(left(Range("a" & i).Value, 1)) Then Rows(i).Delete
    to this:
    Code:
    If Not IsNumeric(left(Range("a" & i).Value, 1)) Then Rows(i).Delete

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Hi Joe, I said i was doing this for testing, just want both to work together to be honest.

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I don't understand your issue/request then.

  5. #5
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    the first code checks the cell if its numeric and deletes as appropriate. But i only want to check the first character in that cell.

    the second one does this but i cant get it working within the code I have.

    I just want it to check the first character of all cells in comumn A. If its blank or begins with a letter then delete it.

    Sorry for any confusion.

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    The second line of code was very temprimental becuase of the way it was written, It would only delete some then i would have to press it again to continue. Also had a problem where the "selection" would stay as the previous range and delete regardless of content of the cell.

    The first box of code would deal with it better i just need to define the "left" with "Ncell" to get them to work together.

    I dont know if im explaining any better, hopefully i am.

  7. #7
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    When deleting rows in Excel, it is always best to work from the bottom up, as deleting rows shifts the range below it up.
    Here is how I would do it:
    Code:
    Sub test()
      
        Dim lastRow As Long
        Dim myRow As Long
         
        lastRow = Cells(Rows.Count, "A").End(xlUp).Row
         
        For myRow = lastRow To 1 Step -1
            If Not IsNumeric(Left(Cells(myRow, 1), 1)) Then Rows(myRow).Delete
        Next myRow
           
    End Sub

  8. #8
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    This is why you are a VIP. Thanks a lot.

  9. #9
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome!
    I was actually an Excel programmer before getting into Access, so I got quite a background in it!

  10. #10
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Im just proficient in persistance haha.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 12-13-2016, 09:48 AM
  2. Code to delete the blank rows
    By drunkenneo in forum Programming
    Replies: 3
    Last Post: 02-17-2014, 09:26 PM
  3. Start Autonumber at a specific number
    By EmptyPage in forum Access
    Replies: 2
    Last Post: 12-20-2013, 02:28 AM
  4. Delete Rows with Same ID and Due Date??
    By taimysho0 in forum Programming
    Replies: 2
    Last Post: 03-01-2012, 12:14 PM
  5. Replies: 0
    Last Post: 02-09-2012, 05:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums