+ Reply to Thread
Results 1 to 13 of 13

VBA Calling Another Sub Routine to Run

  1. #1
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    VBA Calling Another Sub Routine to Run

    Hi,

    I have the following code on sheet12 (tab name Monday).....
    Please Login or Register  to view this content.
    .....which runs when when the sheet is updated. The first part works as required (letters in column E2:E70 are changed to uppercase) however when it gets to the code in 'red', nothing happens.
    The SUB routine I am trying to call is 'Private Sub Monday_R11_Average_Call_Time()' and is written within the <ThisWorkbook> object section.

    I have tried 'Run Monday_R11_Average_Call_Time','Call Monday_R11_Average_Call_Time (which error's)', 'Application.Run Monday_R11_Average_Call_Time' & 'Monday_R11_Average_Call_Time.Call (which error's)'

    Can someone please tell me how I call this SUB routine. Thanks.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA Calling Another Sub Routine to Run

    Why is it in the ThisWorkbook module?

    If you move it to a standard module and remove Private (or replace it with Public) then you'd be able to call the sub like this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: VBA Calling Another Sub Routine to Run

    THANKS - this is now working but it has led onto another error.....
    Please Login or Register  to view this content.
    .....when it gets to the section in 'Red' I get the error MSG "Run-time error '1004': Unable to get the SumIfs property of the WorksheetFunction class".

    Thanks.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA Calling Another Sub Routine to Run

    Marc

    What I suggested wouldn't cause any change in how that code worked.

    Was it definitely working before?

  5. #5
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: VBA Calling Another Sub Routine to Run

    Yes, definetly working before when I 'stepped' through the coding to test.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA Calling Another Sub Routine to Run

    Marc

    Can you post a sample workbook?

    If you can't you could try moving the code back to the ThisWorkbook module, without the Private, and try calling it like this.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: VBA Calling Another Sub Routine to Run

    I've just done a quick test. If I 'Step' through the code it all works whether it is in ThisWorkbook or in it's own module.
    Obviously, calling this SUB didn't work when it was in ThisWorkbook so wasn't able to test it in a 'working environment' but having it setup as suggested means that it does work in the 'working environment' and this error's.

    Any idea's...??

  8. #8
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: VBA Calling Another Sub Routine to Run

    Norie,

    Just tried your suggestion in #6 of this post and it didn't work, error's on
    Please Login or Register  to view this content.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA Calling Another Sub Routine to Run

    Marc

    So when you step through the code it works but when you run the code it errors?

    I really can't see why that would happen.

    Everything appears referenced properly, the formulas look right etc

    Is there anything else going on in the worksheet/workbook?

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA Calling Another Sub Routine to Run

    Quote Originally Posted by mowens74 View Post
    Norie,

    Just tried your suggestion in #6 of this post and it didn't work, error's on
    Please Login or Register  to view this content.
    Did you remove Private?

  11. #11
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: VBA Calling Another Sub Routine to Run

    I know what the problem is....
    Please Login or Register  to view this content.
    I have a number of rows, each row has a 'start time', a 'finish time' and the time difference between each of them. The cell S71 is an overall total of the time difference's giving an overall work time.
    As these cells are calculations, the cell changes from current entry - to #VALUE! - to new calculation but the WorkSheet_Change function see's the change from current total to #VALUE! so it calls the 'Monday_R11_Average_Call_Time' module but the SUMIFs cannot work as the cell is working on has #VALUE! instead of a numeric figure.

    I hope the above makes sense.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA Calling Another Sub Routine to Run

    Marc

    S71 isn't in any of the ranges that are used in the code so I can't see how it could be causing a problem.

    Do any other cells have #VALUE! or any other error?

    Can you attach a sample workbook?

  13. #13
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: VBA Calling Another Sub Routine to Run

    Norie,

    Thank you SO much for your time. Basically, the issue was that the range I was working with was a range of cells that contained results of a calculation. When the calculation updated it went from current figure to #VALUE! to new figure.
    The worksheet_change saw the change from current figure to #VALUE! so the command then started to work but with no figures to work with.

    I have got round this by starting to commands during a save procedure instead (which actually turns out to be better than what I was trying in the first place).
    Please Login or Register  to view this content.
    Unfortunatley, I am unable to attach the spreadsheet into the forum to show (work related and I'm not allowed - sorry).



    Thanks again though for all your help, I have certainly learnt a couple of things

+ 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