Looping Excel VBA Macro that Runs other Macros -
i trying make vba program take stock ticker in column , paste on different "settings" sheet in cell, program execute 2 other vba codes download historical data , backtest formula. program return "data" sheet , print value in "b10" on "settings" column d in "data". need printed value in column d corresponding ticker's row. program has repeat 500 times. can me find how or point out wrong in code? thanks!
sub finalbalance() dim ticker range dim long sheets("results").activate set ticker = activecell = 1 500 sheets("results").activate ticker.select selection.copy sheets("settings").select range("b1").select activesheet.paste application.run "datadownload" application.run "btest" ticker.offset(0, 3) = sheets("settings").range("b10") ticker.address = ticker.offset(1, 0) next end sub
the problem can't assign value .address property:
'instead of ticker.address = ticker.offset(1, 0) 'use: set ticker = ticker.offset(1, 0)
and code working is. however, select statements aren't necessary , should avoided. here's cleaned version of code:
sub finalbalance() dim wsresults worksheet dim wssettings worksheet dim rngstartcell range dim arrresults() variant dim lnumreps long dim long set wsresults = sheets("results") set wssettings = sheets("settings") set rngstartcell = wsresults.range("a2") lnumreps = 500 redim arrresults(1 lnumreps) = 1 lnumreps wssettings.range("b1").value = rngstartcell.offset(i - 1).value application.run "datadownload" application.run "btest" arrresults(i) = wssettings.range("b10").value next rngstartcell.offset(, 3).resize(lnumreps).value = application.transpose(arrresults) end sub
Comments
Post a Comment