0

I am automating some account details, where I DO NOT want them to add double double . for this I need to restrict button click event to once so that they are not added twice or trice. How can I restrict a button click event , otherwise if I change any amount I want button back to update. any help on this please.

 commandbutton1.enable = true
 commandbutton1.enable = false

This is working , but I want button back when ever my account values are changing in cell.

1 Answer 1

1

You can use the Worksheet_Change Event to re-enable the button

Private Sub Worksheet_Change(ByVal Target As Range)
commandbutton1.Enabled = True
End Sub

If you only want the button to be enabled when a certain cell is changed, do it like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then 'Adjust this Cell Address
    commandbutton1.Enabled = True
End If
End Sub

If you want to check for multiple Cells, you can do it like this:

Dim testRange As Range

Set testRange = Range("A1,B3:B10,D5")

If Not Intersect(Target, testRange) Is Nothing Then

    'Do something
    Debug.Print "Target Cell in testRange"
End If

To Check if the changed Cell is in a certain row:

If Target.Row = 2 Then

For Columns:

If Target.Column = 1 Then
Sign up to request clarification or add additional context in comments.

3 Comments

If I want to give multiple cell address how can I do that? As I am having many cells to check.. many rows and many cols to check for change event
@SwethaReddy added some examples to the answer.
Thanks..! Really Helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.