Event
Procedure

*Event*- An *Event* is an action initiated either by user action or by other
VBA code.

As noted above, events are generated by:

·         *The Workbook *

·         *The Worksheets *

·         The Application (User form)

·         Charts



*Event Procedure**:-* An *Event Procedure* is a Sub procedure that you
write, according to the specification of the event, that is called
automatically by Excel when an event occurs

ByVal = *By Value* will change a value inside a Sub

By Val is Copy of Variable and not alter in originally.

ByRef = *By Reference *will Change a value globally.

*ByRef *will point to the Original Variable and represent it

*ByRef(By Default):* If you pass an argument by reference when calling a
procedure the procedure access to the actual variable in memory. As a result
the variable's value can be changed by the procedure.
*ByVal:* If you pass an argument by value when calling a procedure the
variable's value can be changed with in the procedure only outside the
actual value of the variable is retained.

   Event
For example,

(1)-Worksheet_Change
Event

Worksheet object has an event named Change.

Private Sub Worksheet_Change (ByVal Target as Range)

Application.EnableEvents = False


        Target.Value = Target.Value + 1

Application.EnableEvents = True

  End Sub

(2)- Worksheet_SelectionChange

Private Sub Worksheet_*SelectionChange* (ByVal Target As Range)

Sheet1.Range(“A1”).value=12

Sheet1.Range(“B1”).value=13

Sheet1.Range(“C1”).value= Sheet1.Range(“A1”).value+ Sheet1.Range(“B1”).value

End Sub

(3). Worksheet_Activate

Private Sub Worksheet_Activate()

Sheet1.ComboBox1.AddItem ("Noorain")

Sheet1.ComboBox1.AddItem ("Pravesh")

Sheet1.ComboBox1.AddItem ("Rajiv")

End Sub

(4) Worksheet_BeforeDoubleClick

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Target.Cells.Borders.Color = vbRed

End Sub

(5) Worksheet_BeforeRightClick

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)

Target.Cells.Offset(1, 0) = "Noorain"

End Sub

(6) Worksheet_Calculate()

 (6) Automatic Calculation

Private Sub Workbook_Activate()

Application.Calculation = xlCalculationAutomatic

End Sub


-- 
Thanks & regards,
Noorain Ansari
*http://noorain-ansari.blogspot.com/* <http://noorain-ansari.blogspot.com/>


On Sun, Jul 3, 2011 at 9:43 PM, vijayajith VA <vijayajith...@gmail.com>wrote:

> Hi, rajan
>
> Please can you explain event procedure ...
>
>  I have gone thr several sites but still i dont kn how to use event
> procedures
>
> Thankyou
>
>
> On Sun, Jul 3, 2011 at 8:48 PM, Rajan_Verma <rajanverma1...@gmail.com>wrote:
>
>>  Dear All,****
>>
>> If you have any Unsolved Queries From Long time On Group , Pleas Post it
>> again.. We will try to Solve it at earliest****
>>
>> --
>>
>> ----------------------------------------------------------------------------------
>> Some important links for excel users:
>> 1. Follow us on TWITTER for tips tricks and links :
>> http://twitter.com/exceldailytip
>> 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
>> 3. Excel tutorials at http://www.excel-macros.blogspot.com
>> 4. Learn VBA Macros at http://www.quickvba.blogspot.com
>> 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
>>
>> To post to this group, send email to excel-macros@googlegroups.com
>>
>> <><><><><><><><><><><><><><><><><><><><><><>
>> Like our page on facebook , Just follow below link
>> http://www.facebook.com/discussexcel
>>
>
> --
>
> ----------------------------------------------------------------------------------
> Some important links for excel users:
> 1. Follow us on TWITTER for tips tricks and links :
> http://twitter.com/exceldailytip
> 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
> 3. Excel tutorials at http://www.excel-macros.blogspot.com
> 4. Learn VBA Macros at http://www.quickvba.blogspot.com
> 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
>
> To post to this group, send email to excel-macros@googlegroups.com
>
> <><><><><><><><><><><><><><><><><><><><><><>
> Like our page on facebook , Just follow below link
> http://www.facebook.com/discussexcel
>

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/discussexcel

Reply via email to