Link to home
Create AccountLog in
Avatar of stmoritz
stmoritz

asked on

Excel VBA to add + 1 to cell value only if not empty and not a formula

The following code adds 1 to every cell in defined range that has a numeric value. However it also overwrites values that are the result of formulas. It should only overwrite where the cell is a value and non empty but not when there's a formula.

Can I change it like this perhaps:

If IsNumeric(MyCell) And Not IsEmpty(MyCell) And Not IsFormula(MyCell) Then

For Each MyCell In Range("TrkLength")
        If IsNumeric(MyCell) And Not IsEmpty(MyCell) Then
        MyCell.Value = MyCell.Value + 1
        'MyCell.NumberFormat = "0.00%"
    End If
Next MyCell

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of stmoritz
stmoritz

ASKER

perfect! thanks a lot!