WorkSheet_Change VBA that uses another stored Macro

Bowlnhokie

Board Regular
Joined
Apr 23, 2002
Messages
196
I have 20 sheets in an excel workbook that I want to leverage Worksheet_Change events to make updates. Is there a way I can store my Macro in a different module that the On Change event can then call. I would like to do this so If I need to make a change to the Logic, I only have to change it in one module instead of every sheet.

When I run the below code, it errors on "If Target.Address = Target.EntireRow.Address Then Exit Sub" with Run-time error '424' Object required. I am assuming I am not defining something correctly but I am not sure what I need to do.

Any help that can be provided would be appreciated.

Below is my code (probably a little rough)


Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Run "OnEventChange"
    
End Sub

Code:
Sub OnEventChange()

    Dim Cell As Range
    Dim dblEnteredByCol, dblLastEditedCol, dblRangeCount As Double
    Dim dlba, dblb As Double
        
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
               
        dbla = 0
        Do Until Range("A8").Offset(0, dbla).Value = "Entered_By"
            dbla = dbla + 1
            Loop
        dblEnteredByCol = Range("A8").Offset(0, dbla).Column
        
        dbla = 0
        Do Until Range("A8").Offset(0, dbla).Value = "Last_Edited"
            dbla = dbla + 1
            Loop
        dblLastEditedCol = Range("A8").Offset(0, dbla).Column

    If Target.Address = Target.EntireRow.Address Then Exit Sub
    
    dblTargetRangeCount = Range(Target.Address).Count
    
    For Each Cell In Target
        If Cell.Column >= dblPeriodCol And Cell.Column < dblEnteredByCol And Cell.Row > dblPeriodRow Then
        'ActiveSheet.Unprotect Password:=SHEETPASS
            If Cell.Value <> "" Then
                  Cell.Offset(0, dblEnteredByCol - Cell.Column) = Application.UserName
                  Cell.Offset(0, dblLastEditedCol - Cell.Column) = Now
            Else
                  Cell.Offset(0, dblEnteredByCol - Cell.Column).ClearContents
                  Cell.Offset(0, dblLastEditedCol - Cell.Column).ClearContents
            End If

        Else
        End If
    Next Cell
    
        'ActiveSheet.Protect Password:=SHEETPASS, DrawingObjects:=True, Contents:=True, Scenarios:=True _
        ', AllowFiltering:=True
    
    dbla = 0
    dblb = 0
    
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi,

You need to pass Target to the other subroutine.

Something like:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Call OnEventChange(Target)
End Sub
Sub OnEventChange(trgt As Range)
    MsgBox trgt.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top