Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA Excel — Cells, Ranges and Offset : Range

For­mat: Range (“ColumnNameRowNumber”)

Ex: In VBA-Excel when you say Range(“A5”) it’s very easy to under­stand that you are talk­ing about 5th row in 1st col­umn (“A”)

As the name states Range, you can select a range is cells using this function

Ex: Range (“A1:B5”).Copy means copy all the cells between A1 to B5

To know more about Copy/Paste in VBA-Excel click here (link to VBA-Excel Copy Paste)

OR

Range (“A1, A5, A9, C1:C8”).Select

Means select cells A1,A5,A9 and then all the cells from C1 to C8

  • Open a new Excel Work­Book and press “Alt+F11” to open the Visual Basic Editor
  • Copy Paste the fol­low­ing code
Sub FnRangeExp

Dim mainworkBook as WorkBook

Set mainWorkBook  = ActiveWorkBook

mainWorkBook.Sheets(“Sheet1”).Range(“A1:B5”).Value=0

End Sub

Result: In “Sheet1” in all the cells from Range A1 to B5 put ‘0’

 

You may also like...

Leave a Reply

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

%d bloggers like this: