Friday, August 6, 2010

Get to know Range and Cells property in vba

The smallest component in excel is cell follow by range, worksheet and workbook but the most importance is cells itself. If you notice in office 2003 excel column is limit to 256 and row limit to 65536 but more in office 2007. Meaning every sheets we only have 256 x 65536 cells. For column number started from 1 to 256 from left to right but by default A to IV unless you tick R1C1 reference style under Tools->Option->General Tab and for row number start from 1 to 65536 from top to bottom. Therefore before trying to write your own code please remember this otherwise you get stuck in your programming due to this limitation. The question now how to select this cells or range effectively using VBA? Actually there are many ways to apply depending on your program requirement. The methods you can apply as below:
  1. Single cell
    • Range("A1").Select
    • Cells(1,1).Select
  2. Range (Multiple cells)
    • Range("A1:B2").Select
    • Range(Cells(1,1),Cells(2,2)).Select
  3. Rows
    • Rows("1:2").Select
    • Rows(2).Select
  4. Columns
    • Columns("A:B").Select
    • Columns(2).Select
After select (Method if you still remember) then you can change this cells or range properties depending on your program requirement for examples border, fill color and etc. Click here if you have any new project! Let us create for u for free. Thanks

No comments:

Post a Comment