Results 1 to 5 of 5

Text parsing, find string after : character

Threaded View

proepert Text parsing, find string... 02-14-2010, 07:46 PM
martindwilson Re: Text parsing, find string... 02-14-2010, 08:18 PM
proepert Re: Text parsing, find string... 02-14-2010, 08:31 PM
protonLeah Re: Text parsing, find string... 02-14-2010, 09:01 PM
mikerickson Re: Text parsing, find string... 02-14-2010, 10:46 PM
  1. #1
    Forum Contributor
    Join Date
    11-17-2009
    Location
    PA USA
    MS-Off Ver
    Excel 2000
    Posts
    184

    Text parsing, find string after : character

    I am reading lines from a textfile. Each line in the textfile has the identical format:

    textstring1:textstring2

    The two strings are always separated by the : character.

    I have the code to get textstring1, but because I'm a rookie, I can't figure out how to get textstring2.

    See the code in bold, this is the line I need to get textstring2.

    Private Sub CommandButton1_Click()
    Dim FileName As String
      Dim FilePath As String
      Dim FSO As Object
      Dim N As Long
      Dim RegExp As Object
      Dim Text As String
      Dim TextFile As Object
      Dim LineValue1 As String
      Dim LineValue2 As String
      
        FileName = "ocean_def.txt"
        FilePath = "C:\pro\tyco_ocean"
        
        Set RegExp = CreateObject("VBScript.RegExp")
        RegExp.IgnoreCase = True
    
    
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set TextFile = FSO.OpenTextFile(FileName, 1, False, -2)
        N = 1
        
        'Read the data line by line
        Do While Not TextFile.AtEndOfStream
            Text = TextFile.ReadLine
            'Additional code to parse and compare goes here
            'Look for the : character
            If N = 1 Then
                LineValue1 = Trim(Left(Text, InStr(1, Text, ":") - 1))
                LineValue2 = Trim(Right(Text, InStr(1, Text, ":") - 1))   ' I need help with this line            
                a = LineValue1
                b = LineValue2
                Range("F29").Offset(0, 0) = a
                Range("F30").Offset(0, 0) = b
            End If
                    
            N = N + 1
        Loop
        TextFile.Close
    End Sub

    Excel 2000 VBA

    Thank you for helping me.
    Last edited by proepert; 02-14-2010 at 08:29 PM.

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