Consulting

Results 1 to 4 of 4

Thread: clean a row if it doesn't start with a number except _

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    clean a row if it doesn't start with a number except _

    I have this VBA code and it will clean the row that it doesn't start with a number and also i need to add _ and TD that mean also do not clean the row that start with _ or 'TD' also.

    Could you please help me on this subject .

    Thank you very much


    Sub CleanRowifnotnumeric()
         'clean a row if it doesn't start with a number
         
        Dim rng As Range
        Dim cell As Range
         
        Set rng = ActiveSheet.Range("A1:D1").Resize(ActiveSheet.UsedRange.Count, 1)
         
        For Each cell In rng
            If IsNumeric(Left(cell.Value, 1)) = False Then cell.Rows.ClearContents
        Next cell
         
    End Sub

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Sub CleanRowifnotnumeric()
         'clean a row if it doesn't start with a number
        Dim rng As Range
        Dim cell As Range
         
        Set rng = Range("A1", Range("A" & ActiveSheet.UsedRange.Rows.Count))
        For Each cell In rng
                  Debug.Print cell.Rows.Address
            If IsNumeric(Left(cell.Value, 1)) = False And _
              Left(cell.Value, 1) <> "_" And _
              Left(cell.Value, 2) <> "TD" _
              Then cell.Rows.EntireRow.ClearContents
        Next cell
    End Sub

  3. #3
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thank you very much . Big Help like always .

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Sub M_snb()
        For Each cl In Columns(1).SpecialCells(2, 2)
          If Left(cl, 2) = "TD" Or Left(cl, 1) = "_" Then cl.Value = 0
        Next
        Columns(1).SpecialCells(2, 1).EntireRow.ClearContents
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •