+ Reply to Thread
Results 1 to 3 of 3

VBA Search First Number of a String

Hybrid View

  1. #1
    Registered User
    Join Date
    01-19-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    23

    VBA Search First Number of a String

    Hello,
    I am trying to figure out a way to search a range, and if the first number of the string is "0", then delete that row.

    so for example:

    B1 = "0205650"
    B2 = "1256056"
    B3 = "9590004"
    B4 = "0680506"


    The macro would delete rows A1 and A4. Thanks!

    This does not work (obviously), but I need the format something similar.

                          For t = lastrowtracker To 4 Step -1
            If Range(Left("b" & r),1).Value = "0" Then
            Rows(t).Select
                Selection.EntireRow.Delete
    
                Else
                End If
                     Next t
    Thank you!

  2. #2
    Forum Contributor
    Join Date
    06-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: VBA Search First Number of a String

    Try

    Sub test()
    Dim LR As Long, i As Long
    LR = Range("B" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
        If Left(Range("B" & i).Value, 1) = "0" Then Rows(i).Delete
    Next i
    End Sub

  3. #3
    Registered User
    Join Date
    01-19-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: VBA Search First Number of a String

    That worked perfectly! Thank you for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1