ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   creating a formula with a loop (https://www.excelbanter.com/excel-programming/397530-creating-formula-loop.html)

Gary Keramidas

creating a formula with a loop
 
is there an easier way to create a formula in cell than the following. i want to
show the individual amounts as a formula, don't want zero values, though.
ie =20+12+13+6

If IsEmpty(wsA.Range("J" & i)) And cell.Value 0 Then
wsA.Range("J" & i).Formula = "=" & wsA.Range("J" & i).Formula & "+" &
cell.Value
ElseIf cell.Value 0 Then
wsA.Range("J" & i).Formula = wsA.Range("J" & i).Formula & "+" &
cell.Value
End If

--


Gary




Gary''s Student

creating a formula with a loop
 
What you are doing already looks good.

Just be careful of having someing like
=5-2-3
in the cell. Because the result is zero, you will execute the elseif and
loose the "=" sign.
--
Gary''s Student - gsnu2007


"Gary Keramidas" wrote:

is there an easier way to create a formula in cell than the following. i want to
show the individual amounts as a formula, don't want zero values, though.
ie =20+12+13+6

If IsEmpty(wsA.Range("J" & i)) And cell.Value 0 Then
wsA.Range("J" & i).Formula = "=" & wsA.Range("J" & i).Formula & "+" &
cell.Value
ElseIf cell.Value 0 Then
wsA.Range("J" & i).Formula = wsA.Range("J" & i).Formula & "+" &
cell.Value
End If

--


Gary





Gary Keramidas

creating a formula with a loop
 
ok, thanks. it will always be an addition in this case. the cell value is a
cumulative weight.

--


Gary


"Gary''s Student" wrote in message
...
What you are doing already looks good.

Just be careful of having someing like
=5-2-3
in the cell. Because the result is zero, you will execute the elseif and
loose the "=" sign.
--
Gary''s Student - gsnu2007


"Gary Keramidas" wrote:

is there an easier way to create a formula in cell than the following. i want
to
show the individual amounts as a formula, don't want zero values, though.
ie =20+12+13+6

If IsEmpty(wsA.Range("J" & i)) And cell.Value 0 Then
wsA.Range("J" & i).Formula = "=" & wsA.Range("J" & i).Formula & "+" &
cell.Value
ElseIf cell.Value 0 Then
wsA.Range("J" & i).Formula = wsA.Range("J" & i).Formula & "+" &
cell.Value
End If

--


Gary








All times are GMT +1. The time now is 11:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com