Thursday, May 3, 2012

Deleting Empty Rows:-

To delete empty rows in a selected range we can use the following macro. The macro here uses the For Next Loop. First the macro counts the rows in a selected range to determine the when the macro should stop. The For Next statement acts as a counter.
Sub DelEmptyRow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = "" Then    'You can replace "" with 0 to delete rows with 'the value zero
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = True
End Sub
Current Cell Address:-

To get the current cell address (or current range) to perhaps incorporate into your formula, you could use the following code.




Sub MyAddress()

MsgBox ActiveCell.Address 'absolute cell reference with the pesky $ signs

MsgBox ActiveCell.Address(RowAbsolute:=False, columnAbsolute:=False) 'without the $ signs, you may choose to omit either one Row / Column absolute

End Sub
Deleting Range Names :-

To delete all the range names in your workbook, this macro will do the trick.




Sub DeleteNames()

Dim NameX As Name

For Each NameX In Names

ActiveWorkbook.Names(NameX.Name).Delete

Next NameX

End Sub
Emailing Workbook :-

To email your current workbook the following code.



Sub Email()

ActiveWorkbook.SendMail recipients:="julsn@yahoo.com"

End Sub


Collections & Methods

Collections:-
Some objects are collections of other objects. For example, a workbook is a collection of all the objects it contains (ex. sheets, cells, ranges, charts, VBA modules, etc.). A VBA statement that makes reference to the workbook names “Loan Calculator.xls” would appear like this:

Workbooks(“Loan Calculator.xls”)

Methods:-
A method is an action that can be performed on an object. Excel VBA objects are separated from their methods by a period. For example, if you wanted to save a particular file as part of a VBA program you could include the following sentence in the code:

Workbooks(“Loan Calculator.xls”).Save