►("VBA")◄ Cells Method. Cells(5, 3).Formula = "=IF(cells(1, 2) >cells(2, 2),YES, NO)"

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hi.
When I record a macro for the formula IF
IF(B2 > B3, true, false)
of course work
but reading about the Cells method
supposedly B3 and cells(3, 2) are the same thing
so when I substitute then do not work

VBA Code:
Sub Macro1()

    Cells(5, 3).Formula = "=IF(cells(1, 2) >cells(2, 2),YES, NO)"
    
End Sub


Please, tell me what I am missing.

why I want to do this way.
because I would like to use a for next loop
so I will insert variables.

Thank you for reading this
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
It needs to be like
VBA Code:
Cells(5, 3).Formula = "=IF(" & cells(1, 2) & ">" & cells(2, 2) & ",YES, NO)"
 
Upvote 0
Hello, Fluff.
VBA Code:
Sub Fluff()
Cells(5, 3).Formula = "=IF(" & Cells(1, 2) & ">" & Cells(2, 2) & ",YES, NO)"
End Sub
the answer is

#NAME?
 
Upvote 0
Ok, Mr. Fluff, I check again, an now instead of YES and NO, this formula accept only TRUE and FALSE
so now it is working, thank you Mr. Fluff
you help me
VBA Code:
Sub fluff()
Cells(5, 3).Formula = "=IF(" & Cells(1, 2) & ">" & Cells(2, 2) & ",TRUE, FALSE)"
End Sub
now work, :LOL:
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Hello, Fluff.
VBA Code:
Sub Fluff()
Cells(5, 3).Formula = "=IF(" & Cells(1, 2) & ">" & Cells(2, 2) & ",YES, NO)"
End Sub
the answer is

#NAME?
If you want the Yes / No then modify Fluff's formula to this.
But this will hard code the values in the cells, is that really what you are intending.

VBA Code:
Sub FluffMod()
    Cells(5, 3).Formula = "=IF(" & Cells(1, 2) & ">" & Cells(2, 2) & ",""YES"", ""NO"")"
End Sub

Are you sure you don't want something more like this:-
VBA Code:
Sub FluffMod2()
    Cells(5, 3).Formula = "=IF(" & Cells(1, 2).Address & ">" & Cells(2, 2).Address & ",""YES"", ""NO"")"
End Sub

Generates this:- =IF($B$1>$B$2,"YES", "NO")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,445
Messages
6,172,177
Members
452,446
Latest member
walkman99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top