• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Assigning Worksheet change event macro to command button

uday

Member
Hi

I want to assign a worksheet change event macro to command button. It is not reflecting in Macro assigning list.

Regards,
Uday
 

Attachments

I think, you need to assign the target first (you can declare it as a range)
Code:
'Dim ws As Worksheet
'Dim Target As Range, rng As Range
    Set ws = Worksheets("Sheet1")
    Set Target = ActiveCell
    With ws
        If Not Intersect(Target, .Columns(1)) Is Nothing Then
            On Error GoTo bm_Safe_Exit
            Application.EnableEvents = False
            For Each rng In Intersect(Target, .Columns(1))
                rng.Offset(0, 4) = Now
            Next rng
        End If
    End With
bm_Safe_Exit:
If you use a normal button place it in a normal module and use Sub not private sub, for example:
Code:
Sub belle
'your code
End Sub
If you use an active X button, place the code in the sheet and use Private sub with the button name, for example
Code:
Private Sub CommandButton1_Click()
'your code
End Sub
See working example.
No need to use Application.EnableEvents = true, this goes automatically.
Hope this helps.
 

Attachments

Back
Top