IF formula in VBA

Brass Contributor

I am wanting to know if I can do an IF statement in VBA. I tried to research on how to do it but nothing works. I need a formula that states if F49:J50 says "Cont..." then to input a zero if not then leave the number value the same.

 

When I pull data from a different program, it will pull the data from a reference point. So if 123,456 is in the reference point, then I want it to input it into the cell and I want it to keep it there. But if it pulls "Cont..." from the reference point then I want it to input a 0 (zero) in the cell.

2 Replies

@catherine9910 VBA can absolutely do this but why?  If you are asking, I suspect that you aren't too familiar with VBA so a much easier solution would be to use an in-cell formula.  Simply insert another rows/columns or use a set of empty cells and type 

=IF(ISNUMBER(F49:J50),F49:J50,0)

or more accurate to your original request

=IF(F49:J50="Cont...",0,F49:J50)

Note if these 'array' functions don't work for you just replace F49:J50 with F49 and then copy/drag that cell down and then over to cover the corresponding range.

Lastly, if you really need to replace the original  data then you can copy the new data and then paste special -> values only on top of the original data

@catherine9910 

If Condition Then
          Do this
End If