PDA

View Full Version : How to add formula and value to cell VBA



jormarinne
09-07-2011, 05:45 AM
Hola,

I have the following code,

Dim c As Range
Dim d As Range
For Each c In Range("U" + row + ":BC" + row) '.End(xlToRight)
For Each d In Range("U2:BC2")
If d.Value >= eka And d.Value <= toka Then
c.Value = 14
End If
Next d
Next c

In the range C there are formulas in every cell and now i want to add number 14 to the cell but i would not like to lose my formula from the cell, is that possible?

- Antti

Bob Phillips
09-07-2011, 05:51 AM
Don't understand the double loops, but maybe



Dim c As Range
Dim d As Range

For Each c In Range("U" + Row + ":BC" + Row) '.End(xlToRight)

For Each d In Range("U2:BC2")
If d.Value >= eka And d.Value <= toka Then

c.Formula = c.Formula & "+14"
End If
Next d
Next c