Embedding an IF/AND statements within VBA Code

louisepr

New Member
Joined
Nov 5, 2020
Messages
27
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi All

I am trying to replicate this simple formula =IF(AND(L15="Yes", M15="Yes", N15="Yes"),"OK"," ") that works fine in Excel, but cannot get it to work in VBA

ActiveCell.FormulaR1C1 = "=IF(AND(RC[-6]=""Yes"", RC[-5]=""Yes"", RC[-4]=""Yes""),""OK""", """")"
Range("R3").Select
Selection.AutoFill Destination:=Range(Cells(3, 18), Cells(row1 - 1, 18)), Type:=xlFillDefault

Does anyone have a suggestion?

1621749425465.png
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You have an extra quote mark as shown.

1621749821144.png
 
Upvote 0
Solution
BTW, you don't need to 'Select' anything to do most things in vba and Selecting slows your code.
Try this instead
VBA Code:
Range("R3:R" & row1 - 1).FormulaR1C1 = "=IF(AND(RC[-6]=""Yes"", RC[-5]=""Yes"", RC[-4]=""Yes""),""OK"", """")"
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,737
Members
449,050
Latest member
excelknuckles

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