+ Reply to Thread
Results 1 to 19 of 19

Run different macros simultaneously.

  1. #1
    Registered User
    Join Date
    09-19-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    8

    Run different macros simultaneously.

    Hi.
    I am using excel 2010 and I’m facing a problem. Maybe someone can help me.

    I have created 3 different macros, but I want to run them with only one click.

    The big problem is that the second macro should run only when the first is finished, and the third should only run when the second is finished.

    Any tip?

    Regards:
    Bruno

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Run different macros simultaneously.

    Please Login or Register  to view this content.


    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-19-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Run different macros simultaneously.

    To assign this command to a button, I only have to copy that command, changing the macros name, isn't it?
    But it don't work

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Run different macros simultaneously.

    You just run Main from the button
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    09-19-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Run different macros simultaneously.

    Hi,

    This code don't solve my problem!

    My first macro takes too long to be updated, and the second one should only start when the first one is conclude.

    The biggeste problem is the second macro starts when the first one is still running.

  6. #6
    Registered User
    Join Date
    09-19-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Run different macros simultaneously.

    Hi,

    I'm spending to much time to solve this question, but i don't fina a solution.

    Anyone can help me, please.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Run different macros simultaneously.

    I think we'd need to see what your macros do to understand how the second can start before the first has finished. In theory, the example described earlier will (can only) execute the macros sequentially. It is, therefore, hard to understand why that is not the case for you.

    Please post the code and/or a sample workbook (with the code).

    Regards

  8. #8
    Registered User
    Join Date
    09-19-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Run different macros simultaneously.

    My Macro Actualizar takes too long.
    When the third macro start, the first one is not conclude.
    I solve this question run each one individually.

    My Code

    Macro Actualiza

    Sub Actualizar()
    ActiveWorkbook.RefreshAll
    End Sub

    Macro Botão9_Click
    Sub Botão9_Click()
    Sheets("ANÁLISE").Select
    Range("B1:S74").Select
    Range("B2").Activate
    ActiveWorkbook.RefreshAll
    End Sub

    Macro Configurar
    Sub Configurar()
    Sheets("DETALHE").Select
    Cells.Replace What:="JOÃO ROLDÃO", Replacement:="JOAO ROLDAO", LookAt:= _
    xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
    Sheets("ANÁLISE").Select
    Sheets("VENDAS CL").Visible = True
    Sheets("VENDAS CL").Select
    Range("A44").Select
    Cells.Replace What:="ELETTROCANALLI", Replacement:="ELETTROCANALI", LookAt _
    :=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False _
    , ReplaceFormat:=False
    Cells.Replace What:="ITW", Replacement:="ITW(ELEMATIC)", LookAt:=xlWhole _
    , SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
    Cells.Replace What:="TARGETTI", Replacement:="TARGETTI(ESEDRA)", LookAt:= _
    xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
    Range("A48").Select
    Selection.ClearContents
    Range("A47").Select
    Selection.ClearContents
    Range("A45").Select
    Selection.ClearContents
    Range("A47").Select
    ActiveCell.FormulaR1C1 = "CABOS ESPECIAIS"
    Range("A48").Select
    Sheets("VENDAS CL").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("ANÁLISE").Select
    Range("A1:A2").Select


    End Sub

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Run different macros simultaneously.

    Now I have to ask you to follow the forum rules and add Code Tags to your code examples.

    Can you also clarify if you have followed the original guidance and indicate what macro you use to call the others and what order they are called.

    Thanks

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Run different macros simultaneously.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  11. #11
    Registered User
    Join Date
    09-19-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Run different macros simultaneously.

    Hi,

    If you don't mind, i attach my file.

    I'm a beginner with macros, and should have a big mistake!!

    In the code, when the first macro is finish it should call the second and at the end of the second macro should call the third macro.

    But the first one take some time, because it is a update in our intranet.

    Regards
    Attached Files Attached Files

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run different macros simultaneously.

    I am not seeing the command to call the 2nd macro in your first macro.

  13. #13
    Registered User
    Join Date
    09-19-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Run different macros simultaneously.

    on the first macro (actualizar) i put a code Call to call de 2nd macro (Botão9_Click).

    I think it's right, isn't it?

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Run different macros simultaneously.

    I have asked you to add Code tags to your code sample and, now, so has one of the moderators.

    Unless you repond to the request(s), you will be in breach of the forum rules ... and so will I be if I respond to your post.

    Please follow the rules and we can investigate further.

    Regards

  15. #15
    Registered User
    Join Date
    09-19-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Run different macros simultaneously.

    Hope make it right.

    Regards

    Please Login or Register  to view this content.

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Run different macros simultaneously.

    Well, yes ... but, actually, you could have just edited the Post #8 ;-)

    Regards

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Run different macros simultaneously.

    OK, basically, you have three macros:

    Actualizar
    Botão9_Click
    Configurar

    The macro button calls the Actualizar macro. This does a RefreshAll and calls the Botão9_Click macro. This does some "selecting", *another* RefreshAll and then calls the Configurar macro.

    In theory, that would have the same effect as having a Main module as I described earlier if you removed the embedded calls to subsequent macros.

    I think the problem is that a) you execute RefreshAll twice and b) the links are updated in the background. I'm guessing that's why it's taking a while to complete.

    I would recommend removing one of the RefreshAll commands.


    It was a little confusing that you had each of your macros in a separate module. For my benefit, I cut/pasted them all into one module so I could better see the flow.

    I've also tidied up a bit and added ScreenUpdating at the beginning and end of each module. That should make it run smoother.

    Please Login or Register  to view this content.

    Regards

  18. #18
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Run different macros simultaneously.

    Okay, I see what the problem is. Your first macro actually completes very quickly, it tells Excel to Refresh the workbook. Then it moves on to the second macro but meanwhile Excel is busy refreshing all its calculations.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  19. #19
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Run different macros simultaneously.

    maybe making it wait 5 seconds or so would help
    Please Login or Register  to view this content.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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