+ Reply to Thread
Results 1 to 4 of 4

How to check the value of the first letter of a string using the vba array

  1. #1
    Registered User
    Join Date
    04-29-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    5

    How to check the value of the first letter of a string using the vba array

    Hi there,

    Below is some code from a macro I need to change. How do we change the code that is in bold and underlined to VBA.Array(all strings whose first letter does not begin with "D")?
    Sub Delete_Code()

    Dim rngFound As Range, rngToDelete As Range
    Dim strFirstAddress As String
    Dim varList As Variant
    Dim lngCounter As Long

    Application.ScreenUpdating = False

    varList = VBA.Array("AMEX", "CASH", "CC", "CK", "COB", "CONAC", "CONDD", "CONDENT", "CONSG", "CONSG HMO", "DISC", "IBAL", "IDA", "IP", "IPDENT", "IPSG", "IWO", "IWODENT", "MC", "No code", "TIMEPAY", "VISA", "WOA", "WOB", "WOC", "WOD", "WOE", "WOF")

    For lngCounter = LBound(varList) To UBound(varList)

    With Worksheets("DO2").Range("C:D")
    Set rngFound = .Find( _
    What:=varList(lngCounter), _
    Lookat:=xlWhole, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=True _
    )


    If Not rngFound Is Nothing Then
    If rngToDelete Is Nothing Then
    Set rngToDelete = rngFound
    Else
    Set rngToDelete = Application.Union(rngToDelete, rngFound)
    End If

    strFirstAddress = rngFound.Address
    Set rngFound = .FindNext(After:=rngFound)

    Do Until rngFound.Address = strFirstAddress
    Set rngToDelete = Application.Union(rngToDelete, rngFound)
    Set rngFound = .FindNext(After:=rngFound)
    Loop
    End If
    End With
    Next lngCounter

    If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete

    Application.ScreenUpdating = True

    End Sub
    Thanks so much

  2. #2
    Registered User
    Join Date
    04-30-2011
    Location
    Halifax, NS
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How to check the value of the first letter of a string using the vba array

    Instead of changing the array, why not just add a condition as you loop through it?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-29-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: How to check the value of the first letter of a string using the vba array

    Hi Keyston,

    I'm getting an error message "End If without block If"

    How do I go about resolving that?

    Thanks

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to check the value of the first letter of a string using the vba array

    Hi sharrukin

    Don't know about the procedure itself but your missing an "End With"
    Please Login or Register  to view this content.
    That'll solve this issue
    "End If without block If"
    Last edited by jaslake; 05-23-2011 at 06:52 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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