Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
....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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Purge macros | Excel Worksheet Functions | |||
Remove macros from spreadsheet | Excel Discussion (Misc queries) | |||
Enabling macros | Excel Discussion (Misc queries) | |||
Transferring toolbars and macros to other computers | Excel Discussion (Misc queries) | |||
Macros disappear after a file is imported | Excel Discussion (Misc queries) |