Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default retrieving data from a table on a website

There is a internet page with chemical data :

http://spreadsheets.google.com/pub?k...CQ&output=html

It has chemicals in the first column and proerties in adjacent columns.

Is there a way to have a userform lookup a chemical in a textbox from the
websites 1st column and then populate other textboxes with the adjacent data
from the table?

Can anyone help?

Thanks,

Roger
  #2   Report Post  
Posted to microsoft.public.excel.programming
ron ron is offline
external usenet poster
 
Posts: 118
Default retrieving data from a table on a website

On Jan 18, 9:59*am, Roger on Excel
wrote:
There is a internet page with chemical data :

http://spreadsheets.google.com/pub?k...Q5l0ICQ&output....

It has chemicals in the first column and proerties in adjacent columns.

Is there a way to have a userform lookup a chemical in a textbox from the
websites 1st column and then populate other textboxes with the adjacent data
from the table?

Can anyone help?

Thanks,

Roger


Hi Roger...The following code should give you what you want. It finds
the chemical name to search for in cell A2 and places the data of
interest in cell B2. You can polish it by breaking the text string
containing the data into columns and putting in a header for each
column. Also you can adopt it to text boxes rather than cells should
you choose...Ron

Sub Chem_Name()

' Name of chemical of interest is in A2
chem = Range("A2")

' Get the source code from the website
my_url = "http://spreadsheets.google.com/pub?key=twQ35hFIq-
y0N84xQ5l0ICQ&output=html"
Set my_obj = CreateObject("MSXML2.XMLHTTP")
my_obj.Open "GET", my_url, False
my_obj.send
my_var = my_obj.responsetext
Set my_obj = Nothing

' Locate beginning and end of data for chemical of interest
loc_1 = InStr(1, my_var, chem, vbTextCompare)
loc_2 = InStr(loc_1, my_var, "S3", vbTextCompare)

' Extract and data of interest and remove unecessary characters
chem_text = Mid(my_var, loc_1, loc_2 - loc_1)
chem_text = Replace(chem_text, "Acetone", "")
chem_text = Replace(chem_text, "class=", "")
chem_text = Replace(chem_text, "'s2'", "")
chem_text = Replace(chem_text, "<td ", ", ")
chem_text = Replace(chem_text, "<td '", "")

' Put data in B2
Range("B2") = chem_text
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default retrieving data from a table on a website

Looks like a simple WebQuery will get it -

Sub QueryChemicalData()
Dim sUrl As String

' two parts to avoid line wrapping!
sUrl = "http://spreadsheets.google.com/pub?key="
sUrl = sUrl & "twQ35hFIq-y0N84xQ5l0ICQ&output=html"

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & sUrl _
, Destination:=Range("A1"))
.Name = "ChemicalData"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False ' << note default is True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub

' and to update -
Sub RefreshQ()
Dim qt As QueryTable

Set qt = ActiveSheet.QueryTables("ChemicalData")
'qt.BackgroundQuery = False
qt.Refresh

End Sub

Regards,
Peter T



"Roger on Excel" wrote in message
...
There is a internet page with chemical data :

http://spreadsheets.google.com/pub?k...CQ&output=html

It has chemicals in the first column and proerties in adjacent columns.

Is there a way to have a userform lookup a chemical in a textbox from the
websites 1st column and then populate other textboxes with the adjacent
data
from the table?

Can anyone help?

Thanks,

Roger



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with retrieving data from a table GRK Excel Worksheet Functions 4 June 23rd 09 06:07 PM
Retrieving data from a table John in PA Excel Discussion (Misc queries) 4 September 1st 07 10:17 PM
Retrieving data from another table or array .. sansk_23 Excel Worksheet Functions 1 October 26th 06 06:16 PM
Retrieving Exchange Rate Data from a Website PS Excel Programming 4 August 11th 05 11:13 PM
Retrieving Source Data From Pivot Table John Units Excel Programming 1 September 9th 03 08:07 PM


All times are GMT +1. The time now is 07:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"