Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
hdf hdf is offline
external usenet poster
 
Posts: 30
Default UDF won't launch macro

I have created a simple User Defined Function that I had hoped would
launch a specific macro depending on whether the value in a given cell
using the UDF was True or False.

It is not working, so I'm obviously doing something wrong.

When the value the UDF is linked to is FALSE, the UDF cell puts in the
value "0" (which is fine for my needs). But when the value is linked
to the formula is TRUE, the UDF cell gives back the #Value! error and
it does not call the macro I want it to call.

Can someone help explain what I'm doing wrong? Following is the UDF
code I used.
_________

Function LaunchMacro (InputValue As Boolean)

If InputValue = True Then

Application.Run "NamedMacro"

Else

Exit Function

End If

End Function
_________

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default UDF won't launch macro

You need event code for that.

What is the condition and what to launch?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"hdf" wrote in message
oups.com...
I have created a simple User Defined Function that I had hoped would
launch a specific macro depending on whether the value in a given cell
using the UDF was True or False.

It is not working, so I'm obviously doing something wrong.

When the value the UDF is linked to is FALSE, the UDF cell puts in the
value "0" (which is fine for my needs). But when the value is linked
to the formula is TRUE, the UDF cell gives back the #Value! error and
it does not call the macro I want it to call.

Can someone help explain what I'm doing wrong? Following is the UDF
code I used.
_________

Function LaunchMacro (InputValue As Boolean)

If InputValue = True Then

Application.Run "NamedMacro"

Else

Exit Function

End If

End Function
_________



  #4   Report Post  
Posted to microsoft.public.excel.programming
hdf hdf is offline
external usenet poster
 
Posts: 30
Default UDF won't launch macro

Bob,

I'm not sure what you mean by event code.

If I understand your questions, the condition is when the value of a
given cell input as the variable of my new UDF = TRUE launching (or
trying to) a macro that clears and repopulates a named range, as
follows:

cell: A1 = True
cell: A2 =Launchmacro(a1)

If it worked like I had intended it to, when A1 = TRUE it would run
the macro code below. I really don't care what value is put into cell
A2 since my objective is to get the model to run the macro when
A1=TRUE
__________

Sub Reset_Rev5_Col_2_TypeB()

Range("test_clear") = Clear
With Range("test_clear")
.Rows(1).Select
.value = 0
.Font.ColorIndex = 5
End With

With Range("test_clear_col")
.FormulaR1C1 = "=r[-1]c"
.Font.ColorIndex = 1
End With

Application.Goto Reference:="Start"


End Sub
_________

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default UDF won't launch macro

This is all you need then. It will run the macro if you select cell A2 and
A1 is True

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Me.Range("A1") Then Call Reset_Rev5_Col_2_TypeB
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

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"hdf" wrote in message
ps.com...
Bob,

I'm not sure what you mean by event code.

If I understand your questions, the condition is when the value of a
given cell input as the variable of my new UDF = TRUE launching (or
trying to) a macro that clears and repopulates a named range, as
follows:

cell: A1 = True
cell: A2 =Launchmacro(a1)

If it worked like I had intended it to, when A1 = TRUE it would run
the macro code below. I really don't care what value is put into cell
A2 since my objective is to get the model to run the macro when
A1=TRUE
__________

Sub Reset_Rev5_Col_2_TypeB()

Range("test_clear") = Clear
With Range("test_clear")
.Rows(1).Select
.value = 0
.Font.ColorIndex = 5
End With

With Range("test_clear_col")
.FormulaR1C1 = "=r[-1]c"
.Font.ColorIndex = 1
End With

Application.Goto Reference:="Start"


End Sub
_________





  #6   Report Post  
Posted to microsoft.public.excel.programming
hdf hdf is offline
external usenet poster
 
Posts: 30
Default UDF won't launch macro

Bob,

Thanks for your help. I must be doing something wrong, though. Did
you suggest that I simply plug in code in the WS event as you suggest
and ignore the code I created in the standard code module or are the
two sets of code suppose to work in tandem.

If I simply plug in the code you recommended in a WS event, and ignore
my code, it goes what appears to be a loop with the screen flickering
until it seems to get tired and quit.

If I put =LaunchMacro(A1) in cell A2 and put your recommended code in
the WS event, it does the same or the debug error box comes up.

What I'm trying to do is the following:

I have a single cell range called COMFIRM. In this range there is a
standard IF function that will give a TRUE or FALSE answer depending
on other calculations in my worksheet.

Based on the results of CONFIRM, when TRUE, I would like to launch
the code in the macro called Reset_Rev5_Col_2_TypeB

Thanks again for you help.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default UDF won't launch macro

Sorry, I messed up my code. It should be

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A2")) Is Nothing Then
Call Reset_Rev5_Col_2_TypeB
End If
End Sub

I didn't test against your code, but you should keep that macro. But I did
notice one thing. Where is the range Start, not A2 I hope.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"hdf" wrote in message
ps.com...
Bob,

Thanks for your help. I must be doing something wrong, though. Did
you suggest that I simply plug in code in the WS event as you suggest
and ignore the code I created in the standard code module or are the
two sets of code suppose to work in tandem.

If I simply plug in the code you recommended in a WS event, and ignore
my code, it goes what appears to be a loop with the screen flickering
until it seems to get tired and quit.

If I put =LaunchMacro(A1) in cell A2 and put your recommended code in
the WS event, it does the same or the debug error box comes up.

What I'm trying to do is the following:

I have a single cell range called COMFIRM. In this range there is a
standard IF function that will give a TRUE or FALSE answer depending
on other calculations in my worksheet.

Based on the results of CONFIRM, when TRUE, I would like to launch
the code in the macro called Reset_Rev5_Col_2_TypeB

Thanks again for you help.



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
Auto Launch of Macro Daren Excel Discussion (Misc queries) 1 March 20th 07 08:10 PM
VBA - Launch VBA Macro From VB ajocius[_54_] Excel Programming 2 May 18th 06 02:59 PM
Macro launch - Button vs Manual launch , has different results. Wayne Excel Programming 4 February 23rd 05 11:33 AM
Can you use an IF statement to launch a macro? ian123[_34_] Excel Programming 3 January 3rd 04 12:38 AM
Launch Macro in Access via Macro running in Excel??? dgrant Excel Programming 1 September 24th 03 01:38 PM


All times are GMT +1. The time now is 11:33 PM.

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"