Echo_2
Echo_2

Reputation: 71

Excel VBA how to split lines in TextBox to show only first line

stackoverflow community!

Im currently working on a macro that helps me to acquire numerical data from web. The problem arises in different number of digits for certain values, therefore i'm unable to use InSrt/Mid functions properly for all data. For now, InSrt/Mid in the code gives two text lines, first of which is appropriate, and the second is irrelevant. I.e.

Date: 11.04.14 <--- required line

Terfdgid <--- Not required line

Both of these lines appear in UserForm.TextBox.

Can someone please advise the VBA code that will eliminate the second line from TextBox, so that only 1st line will be shown? Unfortunatelly, all my attempts to make it happen were unsuccessful..

Here's the code that i use:

Private Sub CommandButton1_Click()


Set browser = CreateObject("InternetExplorer.Application")
browser.Visible = False


Dim URL As String: URL = "http://www.internet.com"

the_start:

browser.Navigate (URL)

Do
DoEvents
If Err.Number <> 0 Then
browser.Quit
Set browser = Nothing
GoTo the_start:
End If

Loop Until browser.ReadyState = 4

WebText = browser.Document.Body.InnerText


Dim data As String
Dim Nmbr As String

data = "Something:"

If InStr(WebText, data) > 0 Then
WebText2 = Mid(WebText, InStr(WebText, data), Len(data) + 12)
Nmbr = Mid(WebText2, Len(WebText2) - 11, 16)
Else
Nmbr = "0"
End If

UserForm1.TextBox1.Text = Nmbr

MsgBox "Download Complete."

End Sub

Thank you in advance and best regards!

Upvotes: 0

Views: 2421

Answers (1)

Gary&#39;s Student
Gary&#39;s Student

Reputation: 96773

First determine what character is separating the lines of text. If the character is chr(10) then use something like:

UserForm1.TextBox1.Text = Split(Nmbr,chr(10))(0)

Upvotes: 1

Related Questions