VB for worksheet change event

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
Hello Guys,

I got the following code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
        If .Address <> "$A$1" Then Exit Sub
        If .Value <> "" Then
        Range("B1") = "Empty"
            Else
            Range("B1") = "Not Empty"
        End If
    End With
End Sub
This is not working. Can somebody please point me to the mistake I am making in this code? What should I replace with what and why?
Also, if I wanted to make it worksheet calculate eevent where A1 will be result of A2+A3, how would I do it?

Asad
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I am just trying to learn VB coding, That's all. So I am just putting some codes in the sheet and see if it works or not. This one didn't, and I can't understand why is it not working.
Can you please help me understand? Thanks for your help.
Asad
 
Upvote 0
With that A2+A3, I want to get a worksheet calculate event code that will be triggered by this calculation. That's all.
 
Upvote 0
In A1 put = A2 + A3

Right click on the sheet tab >> view code

Code:
Private Sub Worksheet_Calculate()
    If Range("A1").Value = 4 Then
        MsgBox ("That's right")
    End If
End Sub

For the other piece of code you have it appears to be working, but you need to paste it in the worksheet module also.

http://www.rondebruin.nl/code.htm
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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