By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


Select a cell - Range(...).select

Turn on the Macro recorder and position it so you can see Excel and VB Editor at the same time.

Select cell A1. View the code Excel creates.

Range("A1").select


Range is collection??
"A1" is the parameter
Select is the Method

Select various parts of the spreadsheet and notice the code that Excel generates.


You'll see something like
  • Range("A1:C3").Select
  • Range("A1:A4").Select
  • Columns("B:B").Select
  • Rows("3:3").Select

    If you forget how to select things in VBA just record and now you know.

    It will be common to change the range names to make them more flexible.

    For example if you want to select A1 through the last item in column B you'd do the following

    r = FindLastRow(2)
    Range("A1:B" & r).select

    FindLastRow is a UDF (User Defined Function)

    Common Mistakes:
  • Misspelling something
  • Leaving off the " (double quotes)
  • Mismatched Parenthesis
    (2) - is a parameter of column #2
    r - is a variable that gets the result of FindLastRow() function.
    "A1:B" & r - is a concatenation of the strings "A1:B" and the number stored in the variable r

  •