#1   Report Post  
Frazer
 
Posts: n/a
Default IF and Macros.......

Finally one macro problem solved, so i begin another......

is it possible to start a macro using an IF function


i.e if cell 1 shows a 0, the macro is off, but when it changes to 1 the
macro starts running.....

is this possible??

Thnx for help in advance??
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

No it isn't.

You can use conditional formatting to format that cell or event code to pick
up the change and run code based on that change.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frazer" wrote in message
...
Finally one macro problem solved, so i begin another......

is it possible to start a macro using an IF function


i.e if cell 1 shows a 0, the macro is off, but when it changes to 1 the
macro starts running.....

is this possible??

Thnx for help in advance??



  #3   Report Post  
marty
 
Posts: n/a
Default

....is it possible to start a macro using an IF function. Answer: YES


....if cell 1 shows a 0, the macro is off, but when it changes to 1 the macro
starts running. Answer: NO

This would be known as an on change event. As far a I know this is not
possible. The simple answer to your question is, no.


"Frazer" wrote:

Finally one macro problem solved, so i begin another......

is it possible to start a macro using an IF function


i.e if cell 1 shows a 0, the macro is off, but when it changes to 1 the
macro starts running.....

is this possible??

Thnx for help in advance??

  #4   Report Post  
Frazer
 
Posts: n/a
Default

How do i do that??? (Not the conditional formatting part- how can i run code
based on the change), and can this be used to start a macro??

"Bob Phillips" wrote:

No it isn't.

You can use conditional formatting to format that cell or event code to pick
up the change and run code based on that change.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frazer" wrote in message
...
Finally one macro problem solved, so i begin another......

is it possible to start a macro using an IF function


i.e if cell 1 shows a 0, the macro is off, but when it changes to 1 the
macro starts running.....

is this possible??

Thnx for help in advance??




  #5   Report Post  
Nick
 
Posts: n/a
Default

Yes it is. I just wrote knocked this nonsense up:

Put a 1 in cells A1
Put this in cell B1
=IF(A1=1,SillyFunction(A1),"Nada")

Put this in a module:
Public Function SillyFunction(strIn As String) As String
MsgBox strIn
End Function

I'd call that starting a bit of code from an IF function wouldn't you? ;o)

"Bob Phillips" wrote in message
...
No it isn't.

You can use conditional formatting to format that cell or event code to pick
up the change and run code based on that change.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frazer" wrote in message
...
Finally one macro problem solved, so i begin another......

is it possible to start a macro using an IF function


i.e if cell 1 shows a 0, the macro is off, but when it changes to 1 the
macro starts running.....

is this possible??

Thnx for help in advance??







  #6   Report Post  
Bob Phillips
 
Posts: n/a
Default

You misunderstand. Perhaps I was economical with the statement, as you can
run a macro, but you can't do anything meaningful in it, such as setting the
cell colour of another cell. Your example is just throwing up a trivial
message. --

HTH

RP
(remove nothere from the email address if mailing direct)


"Nick" wrote in message
...
Yes it is. I just wrote knocked this nonsense up:

Put a 1 in cells A1
Put this in cell B1
=IF(A1=1,SillyFunction(A1),"Nada")

Put this in a module:
Public Function SillyFunction(strIn As String) As String
MsgBox strIn
End Function

I'd call that starting a bit of code from an IF function wouldn't you? ;o)

"Bob Phillips" wrote in message
...
No it isn't.

You can use conditional formatting to format that cell or event code to

pick
up the change and run code based on that change.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frazer" wrote in message
...
Finally one macro problem solved, so i begin another......

is it possible to start a macro using an IF function


i.e if cell 1 shows a 0, the macro is off, but when it changes to 1 the
macro starts running.....

is this possible??

Thnx for help in advance??







  #7   Report Post  
Bob Phillips
 
Posts: n/a
Default

Here is a simple example

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Address = "$A$1" Then
If .Value = "xxx" Then
'do your stuff
End If
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frazer" wrote in message
...
How do i do that??? (Not the conditional formatting part- how can i run

code
based on the change), and can this be used to start a macro??

"Bob Phillips" wrote:

No it isn't.

You can use conditional formatting to format that cell or event code to

pick
up the change and run code based on that change.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frazer" wrote in message
...
Finally one macro problem solved, so i begin another......

is it possible to start a macro using an IF function


i.e if cell 1 shows a 0, the macro is off, but when it changes to 1

the
macro starts running.....

is this possible??

Thnx for help in advance??






  #8   Report Post  
Frazer
 
Posts: n/a
Default

Ok basically what I am doing is trying to find a way in which the following
macro can be used without me having to run it, as i have too many of them,
which takes a long time:

Sub Macro1()
Dim cnt As Integer
cnt = 1

For Each c In Worksheets("Sheet1").Range("T1:T10").Cells
Range("T" & cnt).Select
On Error Resume Next
Selection.Hyperlinks(1).Follow NewWindow:=False,
AddHistory:=True
cnt = cnt + 1
Next
End Sub

Its a macro that opens up links within a certain range that are in my
spreadsheet.

Basically i need some way to make this work when a certain value, or
conditional formatting, changes in my spreadhseet. I thought i could do this
with an IF function, simply by changing a value, but obviously this does not
work, so I just need some way of making it work.....can you help??

I tried using that code you said before, but to be honest i have no idea
what Im doing, im not really that great on excel, so if you could just
explain it to me as well in lamens terms that would be cool




"Bob Phillips" wrote:

Here is a simple example

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Address = "$A$1" Then
If .Value = "xxx" Then
'do your stuff
End If
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frazer" wrote in message
...
How do i do that??? (Not the conditional formatting part- how can i run

code
based on the change), and can this be used to start a macro??

"Bob Phillips" wrote:

No it isn't.

You can use conditional formatting to format that cell or event code to

pick
up the change and run code based on that change.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frazer" wrote in message
...
Finally one macro problem solved, so i begin another......

is it possible to start a macro using an IF function


i.e if cell 1 shows a 0, the macro is off, but when it changes to 1

the
macro starts running.....

is this possible??

Thnx for help in advance??






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
Purge macros Don_S Excel Worksheet Functions 1 August 16th 05 03:51 PM
Remove macros from spreadsheet Jan Buckley Excel Discussion (Misc queries) 1 August 12th 05 08:38 PM
Enabling macros Peter M Excel Discussion (Misc queries) 3 February 7th 05 10:57 PM
Transferring toolbars and macros to other computers Darrell Excel Discussion (Misc queries) 1 January 19th 05 12:21 AM
Macros disappear after a file is imported Brent E Excel Discussion (Misc queries) 1 December 18th 04 12:25 AM


All times are GMT +1. The time now is 04:30 PM.

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

About Us

"It's about Microsoft Excel"