E Series Macro Examples

Share Now


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



Share Now
October 9, 2011

0 responses on "E Series Macro Examples"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Tableau Training in Delhi

    All Rights Reserved. EC Analytics Consulting 2014 - 2019.

    NM 23, Sector 14, OLD DLF Colony - Gurgaon (Haryana) India. 9582876837 | Privacy Policy

    Drop us a Query

    Call Us: +91 8826547882

    Drop us a Query