+ Reply to Thread
Results 1 to 3 of 3

Thread: Parse with VBA

  1. #1
    Registered User
    Join Date
    04-09-2011
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2003
    Posts
    1

    Parse with VBA

    Hello all!

    I was wondering if someone here could help me out with a VBA problem:

    I'm trying to parse a piece of data, say ( 12.3 13.0 5.5). Ideally, I'd like to "split" it and have the following data:

    number(0) = 12.3
    number(1) = 13.0
    number(2) = 5.5

    My problem is that my "number" array contains spaces (" ") which makes it impossible to parse my data into the correct cells. Due to significant figures, I can never account for the spaces. Can anyone help? It would be much appreciated!

    Thanks,

    sC

  2. #2
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: Parse with VBA

    Welcome to the forum.

    Where does the string come from?

    What do you have so far?
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: Parse with VBA

    Something like this is the data to be split is in a variable.

    Sub z()
    
        Dim vntNumbers As Variant
        Dim strData As String
        Dim lngIndex As Long
        
        strData = " 12.3    13.0  5.5    "
        Do While InStr(1, strData, Space(2), vbTextCompare) > 0
            strData = Replace(strData, Space(2), Space(1))
        Loop
        
        vntNumbers = Split(Trim(strData), Space(1))
        
        For lngIndex = LBound(vntNumbers) To UBound(vntNumbers)
            Debug.Print lngIndex, vntNumbers(lngIndex)
        Next
        
    End Sub
    Cheers
    Andy
    www.andypope.info

+ 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.2.0