Results 1 to 4 of 4

Removing blank lines from string

Threaded View

  1. #1
    Forum Contributor
    Join Date
    11-17-2009
    Location
    PA USA
    MS-Off Ver
    Excel 2000
    Posts
    184

    Removing blank lines from string

    I have a texfile that populates a textbox on a userform. I would like to remove all blank lines in the string including those at the end if they exist, before populating the textbox. I'm reading the entire file at once into the string, not line by line.

    Is there any way to edit the string called Text to remove the blank lines before populating the textbox? I'm looking for 2 carriage return characters in a row, and if so then remove one of them, but I don't know how to code that. This is in the userform activate section.

    If I read the textfile line by line, I don't know how to populate the textbox that way and remove the blank lines.

    Private Sub UserForm_Activate()
    Dim FileName As String
      Dim FSO As Object
      Dim Text As String
      Dim TextFile As Object
      FileName = "C:\Documents and Settings\smith\sample.txt"
      Set FSO = CreateObject("Scripting.FileSystemObject")
      Set TextFile = FSO.OpenTextFile(FileName, 1, False, -2)
      'Read the file into a string
      Text = TextFile.ReadAll
      TextFile.Close
      ' Edit out the blank lines here  
      Me.TextBox1 = Text
    End Sub
    Please see the example workbook and textfile.
    Attached Files Attached Files
    Last edited by proepert; 02-17-2010 at 04:12 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