excel - How can I post a custom equation in a cell based on another cell's value? -


i can't seem figure out why code won't work.

i trying insert formula multiplies cost inflation factor depending on rating inputted. loop goes through 7 rows of data in same column (5), fetches rating, , assigns custom formula based on rating. when go through code step step, values correct , able output correct equation in message box. not sure why can't post cell though... think has fact i'm using range(cells(j, 4)) instead of range("d15")

it's important note named cells inflation1 through inflation5.

ex: if in cell e4 rating 2, code should paste formula =inflation2*d4 in cell d15.

here's code:

sub inflationfactor() dim currentrow long currentrow = 4 dim rating long dim j long j = 15  = currentrow currentrow + 6     rating = cells(i, 5).value     sheet1.range(cells(j, 4)).formula = "=inflation" + str(rating) + "*d" + str(i)     = + 1     j = j + 1 next end sub 


Comments