Call a macro if certain cell >1

Anonymous
2024-10-14T04:28:40+00:00

I would like to run the following macro automatically if cell e24 >1.

It works fine as a macro, but would like it to run automatically.

Can this be edited to make it automatic?

Thanks for your help

Sub DUPLICATES()
If Range("e24") > 1 Then
Cells(Rows.Count, "d").End(xlUp).Select
ActiveCell.ClearContents
ActiveSheet.Range("E24").Select

End If

End Sub
Microsoft 365 and Office | Excel | For home | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Anonymous
    2024-10-21T01:59:14+00:00

    Hi, AZ16

    Thank you for using Microsoft products and publishing them in the community.

    Try this code:

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Me.Range("E24")) Is Nothing Then 
    
        If Me.Range("E24").Value > 1 Then 
    
            Call DUPLICATES 
    
        End If 
    
    End If 
    

    End Sub

    Sub DUPLICATES()

    If Range("E24").Value > 1 Then 
    
        Cells(Rows.Count, "D").End(xlUp).Select 
    
        ActiveCell.ClearContents 
    
        ActiveSheet.Range("E24").Select 
    
    End If 
    

    End Sub

    1. Open an Excel workbook and press Alt + F11 to open the VBA editor.
    2. In the Project Explorer on the left, locate and double-click on the worksheet containing cell E24 (e.g. Sheet1 ).

    I hope the above information can help you. Feel free to send a message if you need further help.

    Best wishes

    Aiden.C - MSFT |Microsoft Community Support Specialist

    0 comments No comments