+ Reply to Thread
Results 1 to 7 of 7

Teach me how to run multiple subs in one module, please?

  1. #1
    Registered User
    Join Date
    02-10-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    65

    Thumbs up Teach me how to run multiple subs in one module, please?

    The first sub here does a great job time-stamping updates to a range within Sheet4.

    The second sub is supposed to time-stamp a cell in Sheet2 based on changes in Sheet4.


    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
    If .Count > 1 Then Exit Sub
    If Not Intersect(Range("A2:A70"), .Cells) Is Nothing Then
    Application.EnableEvents = False
    If IsEmpty(.Value) Then
    .Offset(0, 7).ClearContents
    Else
    With .Offset(0, 7)
    .NumberFormat = "mm/dd/yy hh:mm AM/PM"
    .Value = Now
    End With
    End If
    Application.EnableEvents = True
    End If
    End With
    End Sub
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Me.Range("D2:D1048)").Address Then
    Sheets("Sheet2").Range("C13").Value = Format(Date, "dd-mm-yyyy") & " " & Format(Now, "h:mm:ss AM/PM")
    End If
    End Sub
    Problem is that I do not know enough about VBA syntax to run both within the same module.

    An alternative would be to use a single sub that would, upon updates to a range in Sheet4, time-stamp cells in *both* Sheet4 and Sheet2.


    Thoughts? I really appreciate some of the awesome folks on this forum. Lots of experts, good help, sharp.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Teach me how to run multiple subs in one module, please?

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    02-10-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    65

    Re: Teach me how to run multiple subs in one module, please?

    "Run-time error: '9':
    Subscript out of range."

    It highlights the line

    With Sheets("Sheet2").Range("C13")
    I think this is because I have a range in Sheet4, but want any changes in Sheet4 to make an update to the timestamp in a single cell in Sheet2.

    I can't do target a range to change a single cell, correct?

    Quote Originally Posted by shg View Post
    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    10-13-2010
    Location
    Sunderland, England
    MS-Off Ver
    Excel 2007 (Home) / 2003 (Work)
    Posts
    740

    Re: Teach me how to run multiple subs in one module, please?

    I get the same error message if Sheet2 doesn't exist, other than that shg's code works perfectly - does the sheet definitely have this exact name?

  5. #5
    Registered User
    Join Date
    02-10-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    65

    Re: Teach me how to run multiple subs in one module, please?

    You were right - I had given Sheet2 another name. I updated that, and the code worked.

    Thank you so much!

    Quote Originally Posted by brokenbiscuits View Post
    I get the same error message if Sheet2 doesn't exist, other than that shg's code works perfectly - does the sheet definitely have this exact name?

  6. #6
    Registered User
    Join Date
    02-10-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    65

    Re: Teach me how to run multiple subs in one module, please?

    Solved.

    shg and biscuits - thank you both very much.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Teach me how to run multiple subs in one module, please?

    You're welcome.

+ 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. Multiple subs calling "Declarations" from a singular module
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-02-2014, 12:16 PM
  2. Nesting Multiple Subs
    By cp41 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2013, 03:58 PM
  3. Looping multiple Subs
    By MikeWaller in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2013, 08:20 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. Running multiple subs in one module.
    By ZEvans12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2011, 01:03 PM
  6. Pass variable between subs within module
    By oOarthurOo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-01-2010, 04:58 PM
  7. Exiting Multiple Subs?
    By SS in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-02-2005, 04:05 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