Using IF to decide action

A

a m spock

I have two options to act in ActiveCell depending on value of cell in the
third column to the left of active cell i.e. Offset(0,-3). I have two
separate macros say Macro1 and Macro2 to call depending on if the value is
 
S

Shasur

Hi

You can use like the following

=IF(A3>=1,MAcro2(),Macro1())


where Macro1 and Macro2 are functions like :

Public Function MAcro1()

MAcro1 = "Macro1 Executed "
MsgBox "Macro1 Executed "

End Function

Public Function MAcro2()

MAcro2 = "Macro2 Executed "
MsgBox "Macro2 Executed "

End Function

Cheers
Shasur
 
M

Mike H

Try this

If ActiveCell.Offset(, 3).Value >= 1 Then
'Macro1
ElseIf ActiveCell.Offset(, 3).Value < 1 Then
'macro2
End If

Mike
 
M

Mike H

I should have added that having called a function from a cell in this way the
functionality you then have is very limited. I would need a very compelling
and specific reason before I would do this.
 
A

a m spock

many thanks mike. this is what i needed. will try it out and get back if
there are any issues.
 
A

a m spock

This is what has worked.

If ActiveCell.Offset(0, -3).Value >= 1 Then
Call Sale
ElseIf ActiveCell.Offset(0, -3).Value < 1 Then
Call Sale2
End If

many thanks once again.
 
A

a m spock

dear mike,
in a parallel situations what would need to be done if i need to skip all
action for offset(0,-3).value >=1 and move down in the column until i find a
cell with the corresponding offset(0,-3).value <1 then call macroX

ams
 

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