How to Handle Workbook Condition and Events in Excel VBA beginners

Conditions and Events are actions performed by users which 


trigger Excel VBA to execute code.



Choose Workbook from the left drop-down list. Choose Open from the right drop-down list.



Add the following code line to the Workbook Open Event:

Option Explicit
Private Sub Workbook_Open()
MsgBox "Welcome"

End Sub

Out Put.Once you open that Worksheet you will get message box Notification saying "Welcome"


Worksheet Change Event


Follow the Step 1 and open the Visual basic Editor,
On Visual Basic Editor click Right Drop-down and select Change. 

The Worksheet Change Event listens to all changes on Sheet1. We only want Excel VBA to do something if something changes in 

cell B2. To achieve this, add the following code lines:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
End If
End Sub


5. We only want Excel VBA to show a MsgBox if the user enters a value greater than 80. To achieve

 this, add the following code line between If and End If.

If Target.Value > 80 Then MsgBox "Goal Completed"

6. On Sheet1, enter a number greater than 80 into cell B2.

Enter a Number Greater Than 80

Result:

Workbook Change Event Result

How to Handle Workbook Condition and Events in Excel VBA beginners How to Handle Workbook Condition and Events in Excel VBA beginners Reviewed by Unknown on 23:11 Rating: 5

No comments:

Powered by Blogger.