Free Microsoft Excel 2013 Quick Reference

Running a macro from a conditional formula

I'd like to run one of two different macros I have created based on a Yes or
No answer in a cell. I've tryed the following formula:

=IF(K16="No", Macro "Closed", Macro "Not_Closed)

I was just guessing at the command to run a macro from a cell, but was not
correct.

Any help?

Thanks

JIM


I am running a macro from the private sub code below. The macro I calling for is also stored in the "Objects" area versus the "modules" area--the same place my private sub is located. (Right click on worksheet name, then view code. How do I refer to that place?)


	VB:
	
 Range) 
    If Intersect(Target, Range("a30")) Is Nothing Then 
        Exit Sub 
    Else 
        Call Export 
         
    End If 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
The macro named "export" is executed normally, but the code I'm using--which is basic old stuff--doesn't work like I'm expecting it to. For instance, I get an error message when the macro gets to: Range("o1").Select

I guess the question is can I use regular vba code if my macro resides in the private sub area?

Hi All,

I am trying to run a macro from a UDF but get a error msg: "Expected variable or procedure not module".

Is there a way to get around this or am I doing something wrong.

Hi,

I was wondering if it is possible to run a macro from a cell. That is, if i have a macro which will open a couple of files (like a hyperlink) then is it possible to have some text in a cell "Click here to launch files" which will then run the macro and launch the files?

If all of that is possible, then the further nuisance, is that i have another sheet which uses HLookups to find certain cells, and some of these have links (hopefully these macro-links as mentioned above). If possible, i would also like to beable to use the cell with the Hlookup to load the files (i.e. beable to still run the macro when clicked on).

Hope someone can help,

Regards,

Robert

Does anyone know a method of calling/running a macro from within a cell
function (e.g. a logical IF function)? I am currently using XP Office with
Excel 2002.

Hello,

A beginners question...

I'm trying to run a macro from a drop down list. (searched the forum in vain)

I've created 4 macros, Macro1, Macro2, Macro3, Macro4

I've have a list of names within A1:A4

A1 is called RunMacro1
A2 is called RunMacro2
A3 is called RunMacro3
A4 is called RunMacro4

A1:A4 has been given a Range name of RunMacro_1to4

I've created a dropdown menue in cell F1 via, Data/Validate/ list, source = RunMacro_1to4

How can I assign The macros to this list?

Thanks for any help

I was wondering if it is possible to run a macro from an if statement . I would be very grateful if anyone could help me with this as it would save me alot of time4 and effort.

Is it possible to run a macro from an IF command?

I would like to run a macro automatically bqased upon a change in a
particular cell's condition. As an example:

Cell A1 contains the following formula: =if(b2>b4,"Sell",0)

If A1 = "Sell", I would like to automatically run a macro. Is this possible?

If not, can I automatically run a macro from a formula?

Any help will be greatly appreciated.

Paul

Hi all

Is there a way i can get an excel formula to execute a macro if the conditions are true. eg.

excel formula:

=if(c1>10,(macro),"-"

(macro) to be an autofilter function which I have written. I am looking at automating the macro from the formula rather than someone having to press the assigned button. If there is a simple way, any help would be appreciated

cheers

Rabbi

hey there, i want to run a macro called "macro_2" from a msg box

here the code i already have:

Code:
Response = MsgBox(prompt:="Run Macro?", Buttons:=vbYesNo)
         If Response = vbYes Then
      ????????? heres were the code goes
      Else
      End If
thanx alot,
shy

I'm writing a macro (macro A, WrapUp) to, among other things, run a macro (macro B, Browse_Print_Start) from a different sheet. Macro B is on a protected worksheet that I do not have the password for, but runs fine as a standalone. I can open the worksheet for Macro B, enter my variables, and click a button on the sheet to run the macro. However, when I try to call macro B from macro A, I get a "1004" error. Some of the code that I am trying to use to run this (irrelevant code removed):

Sub WrapUp()
FundName = Range("A4")
GainLossPages = Range("D4")
AppraisalPages = Range("E4")
RunDate = Range("B4")

RunExtract

End Sub

Sub RunExtract()

Application.DisplayAlerts = False

Workbooks.Open "1777_CMOD_Extract_Flexible(1) Custom for PWC Wrapup.xls"

Application.DisplayAlerts = True

Sheets("Flex Request Table").Select
Range("F10").Value = FundName
Range("F11").Value = FundName
Range("H10").Value = RunDate
Range("H11").Value = RunDate
Range("X10").Value = GainLossPages
Range("X11").Value = AppraisalPages

Application.Run "Browse_Print_Start"

'Call "1777_CMOD_Extract_Flexible(1) Custom for PWC Wrapup.xls!Browse_Print_Start"

'Application.Run "1777_CMOD_Extract_Flexible(1) Custom for PWC Wrapup!Browse_Print_Start"
'Application.Run ("Browse_Print_Start")
'"1777_CMOD_Extract_Flexible(1) Custom for PWC Wrapup.xls'!Extract_CMOD"

End Sub

I've also shown some of the other things I've tried that are now commented out. Anyone have any suggestions or workarounds for this? Thanks

i have a search macro which searches for a string provided by the user into a cell (B2) from a list when it finds the value, it returns that row containing the value.

what i want is a method that runs the macro from that cell each time a character is typed into it.

i.e. type the word test should act like

T (run the macro) E (run the macro) S (run the macro) T (run the macro)

i'm using

Code:
Private Sub Worksheet_Change(Target As Range)
If Target.Address = "$B$2" Then
  Call SearchData
End If
End Sub
to make it run when i hit enter after typing in the criteria.

Hi,

I am currently trying to make my first VBA enhanced spreadsheet. It is basically a spreadsheet that uses 2 lookup tables to find values for use in the building construction industry.

My question is this:

I want to have multiple sheets with information on them and a front page that gives options for each sheet (the options are in the form of buttons that the user simply clicks to do as they wish). One of these options will be to print that specific sheet (each sheet has a row of buttons). This is where I seem to run into problems. Without having a macro for each specific sheet how can I use the button to print out the sheet I want.

The current print macro code is as follows:

Sub print_to_pdf( shtname As String)
Sheets(shtname).Select
Application.ActivePrinter = "CutePDF Writer on CPW2:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("Options").Select
End Sub

From my limited knowledge it appears that you cant pass information to a macro from a button press (i.e. print_to_pdf("Sheet1")) you can only pass a 'flat' macro name (i.e. print_to_pdf).

Is there anyway that I can get the button to A. Pass information to a macro Or B. Have the button return its position when it is toggled (if I knew the positon of which button was pressed then I can work back from that to find out which sheet is needed to be printed).

Any other ways round this problem would be greatly appreciated.

I am using windows Xp and excel 2003

Thanks in advance,
Matt.

Is there a way of calling a macro from within another macro?

Example

Sub Button1_Click()
For a = 1 To 10000
Range("A1") . Value = a
Next a
' Would now like to run the macro which is behind Sub
Button2_Click()
End Sub

--
grahammal
------------------------------------------------------------------------
grahammal's Profile: http://www.excelforum.com/member.php...o&userid=20336
View this thread: http://www.excelforum.com/showthread...hreadid=478781

Hi,

I want to run a macro that simply moves data from one row
to an area of the worksheet that keeps track of completed
items. What I need is a statement that does something
like this:

=IF(b1="",do nothing, run move macro).

How do I tell the =IF function to run the macro? This
seems to be a pretty easy thing to go yet the Help does
not address it.

Thanks,

Bob

Is there a way of calling a macro from within another macro?

Example

Sub Button1_Click()
For a = 1 To 10000
Range("A1") . Value = a
Next a
' Would now like to run the macro which is behind Sub Button2_Click()
End Sub

Hi,

I want to run a macro that simply moves data from one row
to an area of the worksheet that keeps track of completed
items. What I need is a statement that does something
like this:

=IF(b1="",do nothing, run move macro).

How do I tell the =IF function to run the macro? This
seems to be a pretty easy thing to go yet the Help does
not address it.

Thanks,

Bob

I have a worksheet with a list of Order Numbers in Column A, starting from cell A1. I want to create a macro that will loop through all the Order Numbers in Column A and for each Order Number do the following:

1. Open a file (GenerateReport.xls) in a folder path (C:temp)
2. Input the Order Number into cell C6 of the Data tab in GenerateReport.xls
3. Run a macro (Gen_Report) in GenerateReport.xls (this macro will create a report based on the Order Number in cell C6 and close the GenerateReport.xls file)
4. Repeat steps 1,2,3 for the next Order Number

Would really appreciate any help that I can get as I am newbie to VBA. Thank you!

Hi all,
I want to run a macro named findandcopyusedrange, present in workbook test.xls, from my new active workbook.
Any suggestions will be appreciated.
Kp

Hi
I have 2 workbooks (Workbook1 and Workbook2).

Workbook 1 contains a button, that calls a macro. This macro calls a macro from Workbook 2.

For this, I am using the Application.Run function.

The Macro in Workbook2 is a simple one line macro that updates cell A2 to a value of 6.

Range("A2").Value = 6

This works fine!

However, I want the the cell A2 in WORKBOOK1 to change to 6, not the cell in Workbook 2.

To add an element of difficulty, Workbook 1 could have any name (I won't know what it is, as the user could change it).

How can I get the Macro in Workbook 2 (Called from Workbook1), to update the cells in Workbook 1.

Hope that made sense.

Thanks guys!

Hi I'm new here.. hopefully somebody can help me with this qeuery...!

I have a list in a worksheet (using 'validation' from the 'data' menu).
I want to run a macro depending on what option is selected from the
list

i.e. if you select 'sheet 1' then the macro called 'macro1' will run...
if you select 'sheet 2' then the macro called 'macro2' will run...etc

is this possible?

many thanks

rufusf

--
rufusf


hi..

i have a form
i accept some user inputs in the form. there is a link on the form from
where i open the excel file in the same browser (not in a new
page...simply using a href. i am also accepting input from the user in
the excel.

now i want to save the data in excel as well as on asp form.
i can save directly thru vba code in excel to the db. but suppose the
user comes back to the form and somehow doesnt click the submit button
of the asp form to save the data. then it would mean that i saved a
certain piece of data in the db thru excel and the other relevant data
didnt get saved at all!

so i revised my approach. now what i want is that when i click the
submit button on the form i want to save the excel data also.

for this what i am doing is...when i open the excel template i let user
enter data inside it and then i will let him a copy of the excel file on
his machine(cleint machine). so in the end when the user clicks the
submit button i will
1. save the form data in database
2. open the excel file stored in clients machine
3. run a procedure inside it whihc save the data in the db

can i open the excel file on button click on asp form and then run a
macro in the excel file?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

I would need to run a macro, in Excel, from a button in a VBA form. Is there a code I need to enter?

Thanks,

Narfcois

Hi again,

I got some really useful help a few weeks ago on how to use the double click event to run a macro from a cell on a worksheet. Now I have started to ponder over whether it would be possible to run a macro from a chart, e.g. by clicking or double clicking on a column. Does this sound remotely feasible?

Many thanks,
fliss