Link to home
Start Free TrialLog in
Avatar of W.E.B
W.E.B

asked on

Excel formula vba

Hello,
can you please help with the formula conditions

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
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

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

Open in new window


Saurabh...
Avatar of W.E.B
W.E.B

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of W.E.B

ASKER

Thank you.