0

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!

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Gary's Student, thank you so much, works perfect! Indeed, lines are separated by "New Line". Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.