excel - #Name? error in cells with VBA code -
i running montecarlo simulation in excel vba receive #name?
errors in respective cells. when click 1 of these cells, press f2
, return
error disappears , value calculated. wrong here?
this code line calculating respective value:
activecell.formula = "=start_rate * exp(norm.s.inv(rand())* standard_deviation * (" & & " ^1/2)) "
and entire code (if necessary):
sub mc_simulation() dim integer dim k integer dim startcell range dim start_row integer dim start_column integer iterations = worksheets("run_mc").range("mc_simulations").value duration = worksheets("run_mc").range("duration").value mean = worksheets("run_mc").range("mean").value start_rate = worksheets("run_mc").range("start_rate").value standard_deviation = worksheets("run_mc").range("standard_deviation").value start_row = 15 start_column = 1 = 1 duration k = 1 iterations worksheets("run_mc").cells(start_row, start_column + i).select selection.value = worksheets("run_mc").cells(start_row + k, start_column).select selection.value = k worksheets("run_mc").cells(start_row + k, start_column + i).select activecell.formula = "=start_rate * exp(norm.s.inv(rand())* standard_deviation * (" & & " ^1/2)) " 'selection.value next k next end sub
you need take vba variables out of quotations:
activecell.formula = "=" & start_rate & "*exp(norm.s.inv(rand())*" & standard_deviation & "*(" & & "^1/2))"
Comments
Post a Comment