If-statement in Macro

  • Thread starter Thread starter fabalicious
  • Start date Start date
F

fabalicious

My macro should check several cells (in the example below it's just one
D10) for their value and based on that, write a 0 or a 1 into cell B4
That works so fine so far (also I have some doubts on the type/forma
of the number written into B4). The value in B4 now should be used a
an argument in an if-statement (still in the macro). Doesn't work
Sometimes executes the 'if' and sometimes the 'else'...

Range("B4").Value = "=IF(D10>2,0,1)"

If Range("B4").Value = 1 Then
...
Else
...
End If

Any help appreciated, cheers

Fabaliciou
 
Try this, it worked for me

Sub test()
Range("b4").Formula = "=IF(D10>2,0,1)"
If Range("B4").Value = 1 Then
MsgBox "The value of B4 is 1"
Else
MsgBox "The value of B4 is 0"
End If
End Sub

HTH
Terry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top