+ Reply to Thread
Results 1 to 3 of 3

Run Macro From If Statement

  1. #1
    Registered User
    Join Date
    05-06-2005
    Posts
    14

    Run Macro From If Statement

    I could be way off here, but... I am trying to do an IF statement and then depending on the answer run a macro or end the statement. In Lotus I was able to do the BRANCH macro, but it seems you cannot do that in excel. This is an example what I'm trying to accomplish.

    If the value of cell M50<= to 25 then do nothing - if it's greater than I need another macro to run.

    Thank you for any help!!

  2. #2
    Ron de Bruin
    Guest

    Re: Run Macro From If Statement

    Hi Paige

    You need a event to do this because formulas can only return values

    You can use the example on this page
    http://www.rondebruin.nl/mail/change.htm

    You see that this example run a mail macro


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl



    "Paige" <Paige.1q0jei_1117739112.6759@excelforum-nospam.com> wrote in message
    news:Paige.1q0jei_1117739112.6759@excelforum-nospam.com...
    >
    > I could be way off here, but... I am trying to do an IF statement and
    > then depending on the answer run a macro or end the statement. In
    > Lotus I was able to do the BRANCH macro, but it seems you cannot do
    > that in excel. This is an example what I'm trying to accomplish.
    >
    > If the value of cell M50<= to 25 then do nothing - if it's greater than
    > I need another macro to run.
    >
    > Thank you for any help!!
    >
    >
    > --
    > Paige
    > ------------------------------------------------------------------------
    > Paige's Profile: http://www.excelforum.com/member.php...o&userid=23096
    > View this thread: http://www.excelforum.com/showthread...hreadid=376081
    >




  3. #3
    Registered User
    Join Date
    05-06-2005
    Posts
    14

    I can't figure it out

    I can't get it to work. How caan I run it from within a Sub? What I am doing is automating a form. When the user chooses the quantities and products it then sorts them and deletes any rows not needed. If there are more than 25 lines I need it to one thing and if it's less another thing. Below is my code up until where I'm stuck. (It may be kind of ugly as I'm quite new to excel...)

    Sub AfterSort()
    Range("A2:I997").Select
    Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("E2") _
    , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    False, Orientation:=xlTopToBottom

    Application.Goto Reference:="PODATABASE"
    ActiveCell.FormulaR1C1 = "end"
    Selection.End(xlUp).Select
    ActiveCell.Offset(1, 0).Activate
    Range(Selection, Selection.End(xlDown)).Select
    Selection.EntireRow.Delete

    Application.Goto Reference:="END1"
    Selection.End(xlUp).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.End(xlToRight).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    ActiveCell.Offset(0, -1).Range("A1").Select

    Range("A2:I27").Select
    Selection.Sort Key1:=Range("I2"), Order1:=xlAscending, Key2:=Range("E2") _
    , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    False, Orientation:=xlTopToBottom
    ActiveCell.Select

    Range("A2:H27").Select
    Selection.Copy
    Sheets("Purchase Order").Select
    Application.Goto Reference:="POQTY"
    ActiveSheet.Paste
    Application.Goto Reference:="POQTY"

    ActiveWorkbook.Names("PODATABASE").Delete
    ActiveWorkbook.Names("PONUMBER").Delete
    ActiveWorkbook.Names("POQTY").Delete
    ActiveWorkbook.Names("POREQUIREDBY").Delete
    ActiveWorkbook.Names("POVALUE").Delete
    ActiveWorkbook.Names("POMERGE").Delete
    ActiveWorkbook.Names("POJOBNO").Delete
    ActiveWorkbook.Names("POVENDOR").Delete

    'THIS IS WHERE I NEED TO HAVE IT CHOOSE BETWEEN CONTINUING IF THE TOTAL IS MORE THAN 25 OR END CODE IF 25 OR LESS

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1