If statement in macro

O

orquidea

Hi

I want the macro to type in column on "c" the status "On Time" or Delayed"
depending of the following criteria:
- if A= MTL and B = 2 then C= "on Time"
- if A<> ATLN OR VAN and B =1 then C ="on time"
- if A=ATLN ot VAN then C="out of ON PU"
- Else "Delayed"

A B c

MTL 2
ATLN 5
VAN 7
LOND 1

I wrote the below proceduce but there is an error. Could anyone help me to
write this procedure properly. Thanks in advance.

Sub Job()

Range ("C1).Select
ActiveCell.Value = "=if ActiveCell.Offset(0,-2)= "MONT" and
ActiveCell.Offset(0,-1)=2 then Active.Cell.Value="On Time"
Else
if ActiveCell.Offset(0,-2) <> "ATLN" or If ActiveCell.Offset(-2,0)<> "VAN"
and ActiveCell.Offset(0,-1)=1 then ActiveCell.Offset.Value="On Time"
Else
if ActiveCell.Offset(0,-2) = "ATLN" or If ActiveCell.Offset(0,-2)= "VAN" then
ActiveCell.Value="Out of ON PU"
Else
ActiveCell.Value="Delayed"
End if

End ()



Orquidez
 
J

Jim Cone

Maybe this...
'--
Function LiesAndMore()
Dim rng As Range
Set rng = ActiveCell

Select Case True
Case Len(rng.Value) = 0
Exit Function
Case rng.Value = "MTL" And rng(1, 2).Value = 2
rng(1, 3).Value = "on time"
Case rng.Value = "ATLN", rng.Value = "VAN"
rng(1, 3).Value = "out of ON PU"
Case rng(1, 2).Value = 1
rng(1, 3).Value = "on time"
Case Else
rng(1, 3).Value = "Delayed"
End Select
End Function
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"orquidea" <[email protected]>
wrote in message
Hi
I want the macro to type in column on "c" the status "On Time" or Delayed"
depending of the following criteria:
- if A= MTL and B = 2 then C= "on Time"
- if A<> ATLN OR VAN and B =1 then C ="on time"
- if A=ATLN ot VAN then C="out of ON PU"
- Else "Delayed"

A B c

MTL 2
ATLN 5
VAN 7
LOND 1

I wrote the below proceduce but there is an error. Could anyone help me to
write this procedure properly. Thanks in advance.

Sub Job()
Range ("C1).Select
ActiveCell.Value = "=if ActiveCell.Offset(0,-2)= "MONT" and
ActiveCell.Offset(0,-1)=2 then Active.Cell.Value="On Time"
Else
if ActiveCell.Offset(0,-2) <> "ATLN" or If ActiveCell.Offset(-2,0)<> "VAN"
and ActiveCell.Offset(0,-1)=1 then ActiveCell.Offset.Value="On Time"
Else
if ActiveCell.Offset(0,-2) = "ATLN" or If ActiveCell.Offset(0,-2)= "VAN" then
ActiveCell.Value="Out of ON PU"
Else
ActiveCell.Value="Delayed"
End if
End ()

Orquidez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top