+ Reply to Thread
Results 1 to 15 of 15

VBA call multiple subs not working correct

  1. #1
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    VBA call multiple subs not working correct

    Hey Dear community,

    I have 20-30 subs , when i run them 1by1 they work right, but when i "call" all of them , i get wrong results. Can anybody help me with this problem please?

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: VBA call multiple subs not working correct

    Stab in the dark & crystal ball gazing may eventually find an answer - BUT there is no better way than analyzing the actual code.
    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: VBA call multiple subs not working correct

    Well, there could be differnt reasons for that. And a lot depends on a code in these subroutines.

    What quite often helps in such cases (especially if I/O operations or calling external programs happens in these pieces of code) is to add DoEvents between rthe calls.

    like
    Please Login or Register  to view this content.

    Sometimes (if you can afford some delay) you could also add there Application.Wait
    Best Regards,

    Kaper

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: VBA call multiple subs not working correct

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA call multiple subs not working correct

    Hey AliGW , can you give me example what you want me to say? provide link where i asked same question?
    like this: https://www.mrexcel.com/board/thread.../#post-5594675

  6. #6
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA call multiple subs not working correct

    Quote Originally Posted by torachan View Post
    Stab in the dark & crystal ball gazing may eventually find an answer - BUT there is no better way than analyzing the actual code.
    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Hello thanks for advice
    Quote Originally Posted by Kaper View Post
    Well, there could be differnt reasons for that. And a lot depends on a code in these subroutines.

    What quite often helps in such cases (especially if I/O operations or calling external programs happens in these pieces of code) is to add DoEvents between rthe calls.

    like
    Please Login or Register  to view this content.

    Sometimes (if you can afford some delay) you could also add there Application.Wait
    i will try this solution now, if it is not works, i will add workbook or code here

  7. #7
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA call multiple subs not working correct

    It is not working... code calculates only first 9 row...
    Here is code..
    Please Login or Register  to view this content.

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,857

    Re: VBA call multiple subs not working correct

    @CWever

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  9. #9
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    Re: VBA call multiple subs not working correct

    Try what Kaper suggested. Add this line before the first call, and also after each call line:

    Application.Wait (Now + TimeValue("0:00:02"))

    It will slow down your code because there will be a 2 second wait after each call but it might fix your problem. So like this:

    Please Login or Register  to view this content.
    If that works, then change the 2 to a 1 to make it a little faster and see if it still works.

  10. #10
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA call multiple subs not working correct

    Hi achammar , thanks for trying help me. I tried your suggestion. Result is same. I think problem is in this code

    Please Login or Register  to view this content.
    When i change "AE25:AE" & lr to "AE25:AE2000" i get correct results. Can you tell me what am i doing wrong?

  11. #11
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    Re: VBA call multiple subs not working correct

    Try changing this:
    Set ResRange1 = Sheets("DATA").Range("AE25:AE" & lr)

    to this:
    Set ResRange1 = Sheets("DATA").Range("AE25:AE" & Trim(Str$(lr)))

  12. #12
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA call multiple subs not working correct

    Quote Originally Posted by achammar View Post
    Try changing this:
    Set ResRange1 = Sheets("DATA").Range("AE25:AE" & lr)

    to this:
    Set ResRange1 = Sheets("DATA").Range("AE25:AE" & Trim(Str$(lr)))

    Not works, forgot to say that range contains text not numbers ( correct result is 135 , i get result 50 )

  13. #13
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    Re: VBA call multiple subs not working correct

    Quote Originally Posted by Akbarov View Post
    Not works, forgot to say that range contains text not numbers ( correct result is 135 , i get result 50 )
    Then I think your problem line is this one:
    lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row

    lr is not getting the right value and is returning the value of the wrong row.
    Last edited by achammar; 11-25-2020 at 06:06 PM.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: VBA call multiple subs not working correct

    How about
    Please Login or Register  to view this content.
    Otherwise you may be calculating the last row on the wrong sheet.

  15. #15
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA call multiple subs not working correct

    Quote Originally Posted by achammar View Post
    Then I think your problem line is this one:
    lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row

    lr is not getting the right value and is returning the value of the wrong row.
    i added your code app.wait + removed lr it works now, thank you very much for help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA to combine/call two subs in Worksheet_SelectionChange(ByVal Target As Range)
    By nate.oyen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2020, 02:11 AM
  2. Add Macro to Call Subs Depending on Cell Value
    By John Maier in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2014, 10:45 AM
  3. Question about call other subs from one macro
    By jnh0 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2013, 04:16 AM
  4. Module Subs executing Private Subs without prompt by code - Totally Lost
    By Ozan Ertem in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 12-26-2012, 05:31 PM
  5. Correct way to call function with 2 args...
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2006, 09:55 AM
  6. Correct Syntax for Calling other Subs
    By Andibevan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2005, 10:05 AM
  7. [SOLVED] Correct way to call active worksheet?
    By Locutis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-02-2005, 02:06 PM

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