View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_7_] Peter T[_7_] is offline
external usenet poster
 
Posts: 162
Default populate =IF(... dynamically in loop, possible?


"Claus Busch" wrote in message
Hi Mike,

Am Thu, 19 May 2016 17:02:37 -0700 schrieb Mike S:

For n = 34 To 81
Cells(n, 4).Formula = "=IF(D31," & Cells(n, 2).Address & " /" &
Cells(31, 4).Address & ", 0)"
Next


you don't need that loop. You can create the formula for the whole range
like Peter wrote.
And you don't have to check for 0. 0 divided by any number is always 0.
Try:
Range("D34:D81").Formula = "=B34/$D$31"



Indeed, but any number divided by 0 results in an error :)

another way in 2007 or later
Range("D34:D81").Formula = "=IFERROR(B34/$D$31,0)"

Peter T