Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Putting data into worksheet instead of showing a message box

0

Hi there. Your tutorials are great. May I ask you what should I write into the code of your Macro named "Get Web Data" to Put Data into a Worksheet instead of "Output the price into a message box". 

Thanks in advance

Answer
Discuss

Discussion

Thanks for asking this in the forum! I was going to ask you to do that in reply to your email but then I noticed your question here, so I'm assuming no email reply is needed now.
don (rep: 1989) Feb 23, '21 at 9:08 pm
Add to Discussion

Answers

0

Hi bng01 and welcome to the Forum.

I agree that Don's tutorials are great. If you're referring to the macro Get_Web_Data which gets data from Yahoo, it ends with a MsgBox statement (after the line  "price = html.getElementsByClassName(...") but you can simply replace the MsgBox line with something like:

Sheet1.Range("B2") = price
(givn "price was defined by the preceding line). That will put the value into cell B2. Change the cell ref (in bold above) to move it elsewhere then add info in an adjacent cell to identify what that value is. You might also like to "timestamp" the value's retrieval by adding a second line like:
Sheet1.Range("C2") = Now
which will put the current date and time in that cell. You may have to resize the cell to see it.

Hope this suits your purposes.

Discuss

Discussion

Thanks John! :) Just to add on to your answer, Sheet1 is the codename of the worksheet, which is what you can see in the Project Explorer in the VBA editor, but you could also change that to Worksheets("Your Visible Sheet Name") if that is easier. It was a great answer, I just wanted to make this clear for newbies or anyone who just might have forgotten)
don (rep: 1989) Feb 23, '21 at 9:06 pm
Good point, thanks Don.
John_Ru (rep: 6142) Feb 24, '21 at 2:36 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login