2 different "Private Subs" into one Sheet

  • I'm fluent in batch files, but lately find myself having to manipulate VBA Code in Excel files to which I'm having varying degrees of success.


    I'm trying to insert 2 different "Private Sub" codes into a worksheet but am finding mixing or combining them too difficult for my skillset.


    One code is to enter the date/time when a specific cell is double clicked - works fine.
    The other code is to save the document without the save box popping up when the document is closed - untested


    I've googled and found a lot of similar posts, but haven't found anything giving me the specific answer/s I need.
    I've included the 2 code's I'm using below. Simply putting one under the other causes an error and the 2nd code to do nothing.
    There is a trick I'm missing.


    Code
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Not Intersect(Target, Range("H1:H1000000")) Is Nothing Then
            Cancel = True
            Target.Formula = Now
        End If
    
    
    
    
    End Sub




    Code
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Application.DisplayAlerts = False
            ActiveWorkbook.Save
        Application.DisplayAlerts = True
    End Sub
  • Re: 2 different "Private Subs" into one Sheet


    Quote from StephenR;793622

    The latter needs to be in the ThisWorkbook module, not a sheet module, as it applies to the workbook. I am guessing that is your issue.



    Nailed It. Thank you very much for your help, you just taught me something :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!