Areas in Excel VBA (Visual Basic for Applications) code example

Areas in Excel VBA (Visual Basic for Applications) code example

Areas

Represents collection of the areas, or contiguous blocks of cells, within a selection. Areas collection contains one Range object for each contiguous range in the selection. An index (a positive integer value) property can be applied to access specific area from Areas collection.

Code example

Sub ClearAreas()
	If Selection.Areas.Count <> 1 Then 
		Selection.Clear
	End If
If Selection.Areas.Count <> 1 Then 
		Selection.Areas(1).Clear
	End If
End Sub

Get Area

Sub GetAreas()
	Set rangeToUse = Selection 
	If rangeToUse.Areas.Count = 1 Then 
		myArea rangeToUse 
	Else 
		For Each singleArea in rangeToUse.Areas 
			myArea singleArea 
		Next 
	End If
End Sub

Properties

  • Application
  • Count
  • Creator
  • Item
  • Parent

Hope you like the post

Leave a Reply

Your email address will not be published.