WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Blog
  • Free Video Tutorials
  • Courses
  • All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA Select Cell

VBA Select Cell

By Jeevan A YJeevan A Y | Reviewed By Dheeraj VaidyaDheeraj Vaidya, CFA, FRM

Excel VBA Select Cell

In VBA selection is done by a keyword method statement known as SELECT statement, select statement is used with the range property method to make any selection, now to select any particular cell we will still use the range property method with the select statement and the cell reference.

In excel, we work with cells and range of the cell. In a regular worksheet, we can select the cell either by mouse, or we reference the cell, as simple as that. However, in VBA, it is not that straight forward. For example, if we want to select the cell A1 using VBA, we cannot simply say “A1 cell”. Rather we need to use the VBA RANGE object or CELLS property.

VBA coding is a language it has specifies a way of doing tasks. Selecting cells in one of those tasks which we need to script in the VBA language. In this article, we will show you how to select the cell using VBA code.

VBA Select Cell

How to Select Excel Cell using VBA?

You can download this VBA Select Cell Excel Template here – VBA Select Cell Excel Template

Example #1 – Select Cell through Macro Recorder

To start off the learning, let’s start the process by recording the macro. Place a cursor on the cell other than the A1 cell.

VBA Select cell Example 1

I have selected the B3 cell as of now.

Now click on the record macro button.

VBA Select cell Example 1-1

As soon as you click on that button, you will see below a window. In this, you can give a new name, or you can proceed with the default name by pressing the OK button.

VBA Select cell Example 1-2

Now we are in B3 cell, so select the cell A1.

VBA Select cell Example 1-3

Now stop the recording.

VBA Select cell Example 1-4

Click on Visual Basic to what it has recorded.

VBA Select cell Example 1-5

Now you will see the recording like this.

VBA Select cell Example 1-6

The only action we did while recording was we have selected the cell A1. So in VBA language, to select any cell, we need to use the RANGE object, then specify the cell name in double-quotes and use the SELECT method to select the specified cell.

Example #2 – Select Cells using Range Object

Now by recording the macro, we get to know to select the cell. We need to use the object RANGE. Now write on your own, type the word RANGE, and open parenthesis.

Code:

Sub Macro1()

Range(

End Sub

VBA Select cell Example 2

Now it is asking what the cell you want to refer to in the range, type “A1” is. Enter the cell address, close the bracket, and type dot (.) to see all the properties and methods available with this cell.

VBA Select cell Example 2-1

Since we need to select the cell, type SELECT as the method.

Popular Course in this category
Sale
VBA Training (3 Courses, 12+ Projects)
4.6 (247 ratings)
3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
View Course

Code:

Sub Macro1()

Range("A1").Select

End Sub

VBA Select cell Example 2-2

Place a cursor in the different cells and run this code to see how it selects the cell A1.

VBA Select cell Example 2-3

Example #3 – Insert Values to Cells

After selecting the cell, what we usually do?

We perform some action. One action is we enter some value. We can enter the value in two ways. One is again using the RANGE object or uses the object ActiveCell,

To insert value by using the RANGE object, again refer to the cell A1 by using RANGE.

VBA Select cell Example 3

This time we are inserting the value, so select VALUE property.

Code:

Sub Macro1()

Range("A1").Select
Range("A1").Value

End Sub

VBA Select cell Example 3-1

To insert value put an equal sign and enter your value in double quotes if the value is text; if the value is numeric, you can directly enter the value.

Code:

Sub Macro1()

Range("A1").Select
Range("A1").Value = "Hello"

End Sub

Example 3-2

Now press the F8 key to run the code line by line to understand the line of codes. On the first press of the F8 key, it will highlight the macro name with yellow, before this select B2 cell.

Now upon pressing the F8 key one more time, it should insert the value “Hello” to the cell A1.

Example 3-3

We can also insert the value by using the Active Cell method.

The moment we select the cell, it becomes an active cell. So use the property active cell to insert the value.

Example 3-4

This is also exactly the same as the last one. Using a range object makes it “explicit,” and using active cells makes it “Implicit.”

Example #4 – Select More than one Cell

We can also select multiple cells at a time. We just need to specify the range of cells to be selected in double-quotes. If you want to select cells from A1 to A5, then below is the way.

Code:

Sub Macro2()

Range("A1:A5").Select

End Sub

Example 4

Run this code using the F5 key or manually to show the result.

Example 4-1

We can also select noncontiguous cells with a range object. For example, if you want to select cells from A1 to A5, C1 to C5, E5 cell, then you can do this like this.

Code:

Sub Macro3()

Range("A1:A5,C1:C5,E5").Select

End Sub

Example 4-2

Run this code manually or through the F5 key to show the result.

Example 4-2

One thing here is we need to start the double quote before we specify any cell then close after the last cell.

Not only cells, but we can also select the named ranges as well by using the name of the range.

Example #5 – Select cells by using CELLS Property

Not through the RANGE object but also through CELLS property, we can select the cells.

VBA Cells

In CELLS property, we need to specify the row number and column number we are selecting. This is unlike a range method where we used A1, A5, C5, C10 like references.

For example, CELLS (1,1) means A1 cell, CELLS (2,5) means E2 cell. Like this, we can select the cells.

Code:

Sub Macro4()

Cells(2, 3).Select

End Sub

Example 4-3

Recommended Articles

This has been a guide to VBA Select Cell. Here we learn how to select an excel cell in using VBA code along with practical examples and a downloadable template. Below you can find some useful excel VBA articles –

  • VBA Range Cells
  • What are Clear Contents in Excel VBA?
  • Text Box in VBA
  • Do Until Loop in VBA
0 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Login

Forgot Password?

WallStreetMojo

Download VBA Select Cell Excel Template

Special Offer - VBA Training Course (6 courses, 35+ hours video) View More