remove non letters from a string

Combat Womble

New Member
Joined
Nov 18, 2015
Messages
30
Hi
I am getting data from a website using VBA and i cant clean the data to just letters. For example I will get "> milkman" instead of "milkman". Below is the code I am using:

Code:
Sub GetData()

Dim IE As New InternetExplorer

'IE.Visible = True
IE.navigate "http://www.anywebsite.com"

Do
    DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

Dim Doc As HTMLDocument
Set Doc = IE.document

Dim Event1 As String
Event1 = Trim(Doc.getElementsByTagName("a")(76).innerText)
Dim Event2 As String
Event2 = Trim(Doc.getElementsByTagName("a")(77).innerText)
Dim Event3 As String
Event3 = Trim(Doc.getElementsByTagName("a")(78).innerText)
Dim Event4 As String
Event4 = Trim(Doc.getElementsByTagName("a")(79).innerText)
Dim Event5 As String
Event5 = Trim(Doc.getElementsByTagName("a")(80).innerText)
Dim Event6 As String
Event6 = Trim(Doc.getElementsByTagName("a")(81).innerText)
Dim Event7 As String
Event7 = Trim(Doc.getElementsByTagName("a")(82).innerText)
Dim Event8 As String
Event8 = Trim(Doc.getElementsByTagName("a")(83).innerText)
Dim Event9 As String
Event9 = Trim(Doc.getElementsByTagName("a")(84).innerText)
Dim Event10 As String
Event10 = Trim(Doc.getElementsByTagName("a")(85).innerText)

MsgBox Event1 & Event2 & Event3 & Event4 & Event5 & Event6 & Event7 & Event8 & Event9 & Event10


End Sub

Thanks in advanced
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
What about spaces between words... should they be retained or did you really just only only letter returned?
 
Upvote 0
no spaces - just letters.
This function will return only letters for any text passed into it...
Code:
Function LettersOnly(TextIn As String) As String
  Dim X As Long
  LettersOnly = TextIn
  For X = 1 To Len(LettersOnly)
    If Mid(LettersOnly, X, 1) Like "[!A-Za-z ]" Then Mid(LettersOnly, X) = " "
  Next
  LettersOnly = Replace(LettersOnly, " ", "")
End Function
So, while I am not really all that familiar with HTML documents, I am guessing the first Trim line of code in the procedure you posted in Message #1 could be replaced with this...
Code:
Event1 = LettersOnly(Doc.getElementsByTagName("a")(76).innerText)
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,772
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top