Need Help! web query macro.

gger

New Member
Joined
Jan 5, 2011
Messages
25
Hi Guys,

I am new to this so be patient. I am looking to create a button that pulls data from a website based on the content of a cell. I have attempted to use the macro recorder to copy the content of a cell, run a web query (to: http://www.financialpost.com/) and paste the copied cell value into the stock quote search box on the right hand side. I want it to select the ticker, go to financials and import the balance sheet to cell B15. Ideally, I would want it to import all the financials for that ticker (balance sheet, cash flow, income statement) and import it on the sheet with the data side by side.

I have run in to two problems:
1. I can get it to run the macro, but regardless of the content of the copied cell (the ticker), it will only return data from the ticker i used to create the macro.

2. If i click the button more than once, instead of clearing data from the earlier search it will return data next to the earlier data. I would prefer if it wiped the previous search and returned the data in B15.

Ultimately, my goal is to be able to input a ticker in a specific cell, press the "run" button, and have the income statement, cash flow statement, and balance sheet statement data pop up on my "Data" sheet.

This is my code at the moment:

Private Sub CommandButton1_Click()
'
' Macro5 Macro
' Macro recorded 05/01/2011 by gger
'

'
Range("B7").Select
ActiveCell.FormulaR1C1 = "AAPL"
Range("D14").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://idms.financialpost.com/stocks/balance_sheet.idms?SYMBOL=AAPL&ID_NOTATION=253929" _
, Destination:=Range("D14"))
.Name = "balance_sheet.idms?SYMBOL=AAPL&ID_NOTATION=253929"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = """IDMS_BalanceSheet"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
Any thoughts?
Thanks in advance,

gger.
 
this is a difficult method to use though because the value can change depending on the type of data i import... so it could be 12.2M in one instance, or 122.2M in another.

is there a way through a formula to delete the last character in a cell? that might be easier...
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I'm a bit confused though. That formula will remove the last character in a cell, whether it'd be

<TABLE style="WIDTH: 60pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=80 border=0><COLGROUP><COL style="WIDTH: 60pt" width=80><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 60pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=80 height=20>48.6M</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>434333.4M</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>3323.774M</TD></TR></TBODY></TABLE>

or anything. I think I may be confused with what you want to do?
 
Upvote 0
That's exactly what I am looking for... but:

=LEFT("CELL", LEN("CELL")-1)

If i replace CELL with the cell D5 (=LEFT("D5", LEN("D5")-1)), it only returns a D...? Playing around with it a bit, if i replace CELL with the content of cell D5 (12.2M, for example) then it will give me 12.2, but thats the exact problem i am trying to get around... not wanting to retype each 12.2M to 12.2.
 
Upvote 0
Hmmm, that's weird. It works for me.
Probably something to do with the fact that you're getting your data from an outside source. Let me give it a whirl with those numbers.

Alright, awesome! Glad I could help out.
 
Last edited:
Upvote 0
no need! silly mistake. I didn't get rid of the quotation marks in the formula. Thanks for the help!
 
Upvote 0
oh no... i also need a formula to delete the first and last characters in a cell as well...

Ex. $12.5M ---> 12.5

thoughts on that one?
 
Upvote 0
gger, you may also want to consider getting the data from Yahoo Finance instead of Financial Post. From my experience when it comes to dealing with financial statements, price quotes, etc, yahoo is much easier to work with than other financial sites. (Will have less formatting issues and so on.)
 
Upvote 0
your amazing, thanks!

one last problem... i want to be able to get rid of these characters so that i can do calculations with the numbers that are left... for some reason it won't let me. would you happen to know why?

ex. D5 becomes 1.5, D6 becomes 1, but =sum(D5,D6) does not equal 2.5, it returns a 0?
 
Upvote 0
Put the formula inside a =VALUE() formula. That fixes the problem. But as mentioned above, using Yahoo finance would be easier I believe!

**So it would look like =VALUE(MID("CELL", 2,LEN("CELL")-2))
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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