Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default If statement in macro

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


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,549
Default If statement in macro

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"
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


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default If statement in macro

Thanks!

"Jim Cone" wrote:

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"
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro or if statement CHARI Excel Worksheet Functions 2 December 8th 06 09:56 PM
Run Macro From If Statement Paige Excel Discussion (Misc queries) 2 June 2nd 05 11:37 PM
If statement in a Macro Dave Excel Discussion (Misc queries) 1 January 29th 05 01:17 AM
if statement in Macro John Excel Worksheet Functions 6 December 29th 04 08:17 PM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 05:46 PM


All times are GMT +1. The time now is 06:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"