# Excel formula vba

Hello,

Dim LastRow As Long
Sheets("Orders").Select
LastRow = Range("A" & Rows.Count).End(xlUp).Row
With Range("AF2:AF" & LastRow)
.Formula =

IF CELL (Z2 = 109 OR Z2 = 313) AND CELL (E2 = MONDAY_12 OR E2 = MONDAY_17) THEN CELL AF2 = RUN 1
IF CELL (Z2 = 109 OR Z2 = 313) AND CELL (E2 = TUESDAY_12 OR E2 = TUESDAY_17) THEN CELL AF2 = RUN 2
IF CELL (V2 Starts with "K") AND CELL Z2 = 124 THEN CELL AF2 = OTTAWA
ANYTHING ELSE CELL AF2 = OTHER

End With
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Use this..

``````Sheets("Orders").Select
LastRow = Range("A" & Rows.Count).End(xlUp).Row
With Range("AF2:AF" & LastRow)
.Formula = "=IF(AND(OR(Z2=109,313),OR(E2=""Monday_12"",E2=""Monday_17"")),""RUN 1"",IF(AND(OR(Z2=109,313),OR(E2=""Tuesday_12"",E2=""Tuesday_17"")),""RUN 2"",IF(AND(LEFT(TRIM(V2),1)=""K"",Z2=124),""OTTAWA"",""Other"")))"
End With
``````

Saurabh...
0
Author Commented:
Hello,
not quite , it's not recognizing the conditions properly,

Example
MONDAY_17     J6RXXX        124      is showing as   RUN 1 (Should be OTHER)
MONDAY_17     K0A2A0        124      is showing as   RUN 1 (Should be OTTAWA)

Thanks
0
Commented:
Use this..

``````Sheets("Orders").Select
LastRow = Range("A" & Rows.Count).End(xlUp).Row
With Range("AF2:AF" & LastRow)
.Formula = "=IF(AND(LEFT(TRIM(V2),1)=""K"",Z2=124),""OTTAWA"",IF(AND(OR(Z2=109,Z2=313),OR(E2=""Monday_12"",E2=""Monday_17"")),""RUN 1"",IF(AND(OR(Z2=109,313),OR(E2=""Tuesday_12"",E2=""Tuesday_17"")),""RUN 2"",""Other"")))"

End With
``````

Saurabh...
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thank you.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.