vba - How to run excel macro periodically and paste updated data into new column -
vba - How to run excel macro periodically and paste updated data into new column -
i have api
fed excel
downloads stock prices url
. column a2:a194
company name, b2:b194
corresponding stock prices.
i want create macro
runs every 5 minutes, fetches new prices , pastes them adjacent column.
this have been able accomplish far:
[sub getprice() ' ' getprice macro ' ' keyboard shortcut: ctrl+q ' activeworkbook.refreshall activecell.offset(0, -1).range("a1").select range(selection, selection.end(xldown)).select selection.copy activecell.offset(0, 1).range("a1").select selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false activecell.offset(-1, 0).range("a1").select application.cutcopymode = false activecell.formular1c1 = "=now()" activecell.select selection.copy selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false activecell.offset(1, 0).range("a1").select application.cutcopymode = false activecell.offset(0, 1).range("a1").select application.ontime + timevalue("00:05:00"), "getprice" end sub]
this macro pulls info previous column instead of b2:b194
. how alter same?
eg: @ end of 1 hour, want 14 columns have data: original 2 + 12 columns fetched cost every 5 minutes.
along lines of why it's pulling previous column. it's because using offset instead of declaring columns want utilize specifically. if know it's going be:
sheets("sheet1").range("b2:b194")
then edit macro defines part.
the macros great way thought of going on in code, i'd edit them more efficient or easier read. mainly, because much of macros depend on user clicking , activating cells constantly, isn't necessary value inserted somewhere or function executed. can see going on in background quickly, looking questionable.
excel vba excel-vba
Comments
Post a Comment