VBA IF(AND difficulty

poikl

Active Member
Joined
Jun 8, 2002
Messages
466
Platform
  1. Windows
Hi,
Can you please help correct structure of the VBA code on my Excel sheet?
I presently have (with MR EXCEL's help in the past) :
Cells(c.Row, "J").Formula = "=IF(LEFT(RC[-1],1)<> RC[-2],""ALERT"","""")"
I'm trying to modify it by adding an AND function to catch if the most left character in ColI (RC[-1],1) has the letter R then instead of showing "ALERT" it should show "NS".
The code I've tried but isn't working is: Cells(c.Row, "J").Formula = "=IF(AND(LEFT(RC[-1],1)<> ""R"",LEFT(RC[-1],1)<>RC[-2],""ALERT"",IF(LEFT(RC[-1],1)= ""R"",""NS"","""")"
Can you please help correct this?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
What is the criteria for the formula to return ""?
 
Upvote 0
If the left most character in ColI RC[-1],1 = ColH RC[-2] then it show blank in ColJ
 
Upvote 0
Then maybe...
Code:
Cells(c.Row, "J").FormulaR1C1 = "=IF(LEFT(RC[-1],1)=RC[-2],"""",IF(AND(LEFT(RC[-1])<>""R"",LEFT(RC[-1],1)<>RC[-2]),""ALERT"",""NS""))"
 
Last edited:
Upvote 0
Mark, Thank you so much. It's perfect and especially very grateful for your immediate reply.
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,315
Members
448,564
Latest member
ED38

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