+91-8826547882

E Series Macro Examples

End Method

You can use the End of the Range object to select a particular. See this example…

Sub EndDemo ()

Range(ActiveCell, ActiveCell.End(xlDown)).Select        ‘select downward the activecell to last non-empty cell

Range(ActiveCell, ActiveCell.End(xlUp)).Select             ‘select upward the activecell to last non-empty cell

Range(ActiveCell, ActiveCell.End(xlToLeft)).Select      ‘select to the left of  the activecell to last non-empty cell

Range(ActiveCell, ActiveCell.End(xlToRight)).Select    ‘select to the right of  the activecell to last non-empty cell

End Sub

Err

The default syntax of Excel VBA. This example demonstrates error handling by jumping to a label..

Sub ErrDemo ()

Dim x As Integer

On Error GoTo ErrorHandler

x = “abc”

Exit Sub

ErrorHandler:

e = Err.Number & ” …cannot assign integer value to x”

MsgBox (e)

End Sub

 

Exit Sub

The Exit Sub statement is use as a point of exiting a subroutine with running the rest of any other statement in a procedure. The example below will display a message box to prompt the user whether to continue or not. If user choose yes, the subroutine will call the macro MyProcdure and will exit the current subroutine.

Sub ExitSubDemo ( )

msg = “Do you want to continue?”

answer = MsgBox(msg,vbYesNo)

If answer = vbYes Then

Call MyProcedure

Exit Sub

Else

MsgBox “Program will end now.”

End if

End Sub

October 9, 2011

0 Responses on E Series Macro Examples"

Leave a Message

© copyright www.excelcrazy.com. All rights reserved. Design and Development by www.creativebrainweb.com