+ Reply to Thread
Results 1 to 4 of 4

Parsing a String (zipcode) [Excel 14/2010, VBA Only)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Parsing a String (zipcode) [Excel 14/2010, VBA Only)

    I need help with the following code as I do not know how to read a string and return the 1st three values.

    Sub test()
    
        Dim iZip As String, parsed_zip As Variant
    
        valid = False
        Do Until valid = True
        iZip = Application.InputBox(prompt:="Enter Zipcode", Title:="Zipcode", Left:=300, Top:=250, Type:=1)
        If iZip <> Empty And iZip <> "False" Then
                valid = True
            End If
        Loop
        inp_form.Range("F5").Value = iZip
        
        'need code to read 1st 3 digits of iZip and output to variable parsed_zip
        
        Select Case parsed_zip
            Case 620 To 629
            Case Else
        End Select
    
    End Sub

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Parsing a String (zipcode) [Excel 14/2010, VBA Only)

    Hi

    parsed_zip = val(left(iZip,3))
    Assuming that there is something in iZip that is 3 or more characters long....

    rylo

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Parsing a String (zipcode) [Excel 14/2010, VBA Only)

    One way:

    Sub test()
        Dim sZip      As String
    
        Do
            sZip = Application.InputBox(Prompt:="Five-digit Zip?", _
                                        Title:="Zipcode")
            If StrPtr(sZip) = 0 Then Exit Sub   ' user canceled
        Loop Until sZip Like "#####"
    
        Select Case CLng(Left(sZip, 3))
            Case 620 To 629
                '...
            Case Else
                '...
        End Select
    End Sub
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Parsing a String (zipcode) [Excel 14/2010, VBA Only)

    I am so LOL'ing at how simple the solution was.
    I really appreciate the help. Thank you!!

+ 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