Subscribe for Weekly Tutorials
BONUS: subscribe now to download our Top Tutorials Ebook!
Select Cells in Excel using Macros and VBA
This is actually a very easy thing to do and only requires a couple lines of code. Below I will show you how to select a cell or a range of cells on the currently active or visible worksheet in Excel.
The simplest way to this is with a macro like this:
Sub Select_Cells_in_Excel()
'Select a single cell in the current worksheet
Range("C4").Select
'Or
Cells(4, 3).Select
End Sub
Copy and paste this into your Excel workbook and read the comments, which will appear in green, to follow everything.
The basic way to select a cell in the currently active worksheet in Excel is to use this method:
Range(A1).Select
This is pretty simple to understand. All you have to do is to change A1 to whichever cell you want to be selected. Thats it!
I prefer to use the range method since it is the simplest way to select a cell. When you create more advanced macros in VBA you may need to use the Cells method.
Cells(4,3).Select
This sample is in the macro above and it points you to cell C4. The first number is the row of the cell to select, 4, and the second number is the column, 3. To get the column number you just count from 1, which is the letter A down to the letter column you wish to reference. A =1, B=2,C=3, etc.
So, you can see that it is actually very easy to select a cell in Excel using macros and VBA. If I were you, I would stick to using the Range method of doing this just because it is so much easier to tell which cell is being referenced just by looking at the code in question.
Question? Ask it in our Excel Forum
Tutorial: This Excel VBA tutorial focuses specifically on selecting ranges of cells in Excel. This...
Tutorial: How to use VBA/Macros to iterate through each cell in a range, either a row, a column, or ...
Tutorial: Make a file selection browser in Excel using VBA/Macros - this is the file window that al...
Tutorial: This macro allows you to have a cell automatically locked after a user enters something in...
Tutorial: Ill show you how to loop through all of the worksheets in a workbook in Excel using VBA an...
Tutorial: How to center a title across multiple cells in Excel in order to make good looking titles...