Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default Problems creating my own ifmacro function

Hi, I made a cutom function but it's not working (the #Value error is shown),
i attached the code so you can see it:

Public Function ifmacro(m0 As String, m1 As String, m2 As String, m3 As
String) As String
If m0 = m1 Then
DoCmd.RunMacro m2
Else
DoCmd.RunMacro m3
End If
End Function

as you can see if I put in cell A7 the following text
"=ifmacro(A1;A2;"Macro1";"Macro2")" and the values of A1=3 and A2=3 then A1=A2
so Macro1 should be executed, but this not happend, the #value error appears
instead.
questions:
1) Why my function is not working???
2)How to change The m0 and m1 variables to just one (like the if function
"=if(A1=A2;....................................... .)")?????
TIA.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problems creating my own ifmacro function

There is no doCmd in Excel. This is an Access VBA command.

Perhaps replace with

Application.Run m2

although this isn't allowed in a UDF used in a worksheet. For you second
question.

Public Function ifmacro(bval As Boolean, m2 As String, m3 As String) As
Boolean
If bval Then
macro1
Else
macro2
End If
ifmacro = bval
End Function

--
Regards,
Tom Ogilvy


"filo666" wrote in message
...
Hi, I made a cutom function but it's not working (the #Value error is

shown),
i attached the code so you can see it:

Public Function ifmacro(m0 As String, m1 As String, m2 As String, m3 As
String) As String
If m0 = m1 Then
DoCmd.RunMacro m2
Else
DoCmd.RunMacro m3
End If
End Function

as you can see if I put in cell A7 the following text
"=ifmacro(A1;A2;"Macro1";"Macro2")" and the values of A1=3 and A2=3 then

A1=A2
so Macro1 should be executed, but this not happend, the #value error

appears
instead.
questions:
1) Why my function is not working???
2)How to change The m0 and m1 variables to just one (like the if function
"=if(A1=A2;....................................... .)")?????
TIA.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default Problems creating my own ifmacro function

Thanks tom; There is some way to do what I want????, if not, thanks anyway,
you information was helpfull.


"Tom Ogilvy" wrote:

There is no doCmd in Excel. This is an Access VBA command.

Perhaps replace with

Application.Run m2

although this isn't allowed in a UDF used in a worksheet. For you second
question.

Public Function ifmacro(bval As Boolean, m2 As String, m3 As String) As
Boolean
If bval Then
macro1
Else
macro2
End If
ifmacro = bval
End Function

--
Regards,
Tom Ogilvy


"filo666" wrote in message
...
Hi, I made a cutom function but it's not working (the #Value error is

shown),
i attached the code so you can see it:

Public Function ifmacro(m0 As String, m1 As String, m2 As String, m3 As
String) As String
If m0 = m1 Then
DoCmd.RunMacro m2
Else
DoCmd.RunMacro m3
End If
End Function

as you can see if I put in cell A7 the following text
"=ifmacro(A1;A2;"Macro1";"Macro2")" and the values of A1=3 and A2=3 then

A1=A2
so Macro1 should be executed, but this not happend, the #value error

appears
instead.
questions:
1) Why my function is not working???
2)How to change The m0 and m1 variables to just one (like the if function
"=if(A1=A2;....................................... .)")?????
TIA.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problems creating my own ifmacro function

Use a case statement with the calls to the macros hardcoded.

--
Regards,
Tom Ogilvy

"filo666" wrote in message
...
Thanks tom; There is some way to do what I want????, if not, thanks

anyway,
you information was helpfull.


"Tom Ogilvy" wrote:

There is no doCmd in Excel. This is an Access VBA command.

Perhaps replace with

Application.Run m2

although this isn't allowed in a UDF used in a worksheet. For you

second
question.

Public Function ifmacro(bval As Boolean, m2 As String, m3 As String) As
Boolean
If bval Then
macro1
Else
macro2
End If
ifmacro = bval
End Function

--
Regards,
Tom Ogilvy


"filo666" wrote in message
...
Hi, I made a cutom function but it's not working (the #Value error is

shown),
i attached the code so you can see it:

Public Function ifmacro(m0 As String, m1 As String, m2 As String, m3

As
String) As String
If m0 = m1 Then
DoCmd.RunMacro m2
Else
DoCmd.RunMacro m3
End If
End Function

as you can see if I put in cell A7 the following text
"=ifmacro(A1;A2;"Macro1";"Macro2")" and the values of A1=3 and A2=3

then
A1=A2
so Macro1 should be executed, but this not happend, the #value error

appears
instead.
questions:
1) Why my function is not working???
2)How to change The m0 and m1 variables to just one (like the if

function
"=if(A1=A2;....................................... .)")?????
TIA.






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
Problems creating a result based on 2 cells being true.. Lucky[_3_] Excel Worksheet Functions 3 May 31st 08 01:49 PM
Problems Creating and Saving Add-in JackRazz Setting up and Configuration of Excel 1 February 1st 08 09:00 AM
Having problems creating a cube venetianjigsaw Excel Worksheet Functions 0 January 26th 06 03:16 PM
I am having problems creating pivot table of data wyman Charts and Charting in Excel 1 January 12th 05 05:17 PM
Problems creating a chart with VBA NooK[_18_] Excel Programming 1 July 3rd 04 06:01 PM


All times are GMT +1. The time now is 05:10 AM.

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"