Using a variable to select a row index in excel.

Posted on 2001-09-07
Last Modified: 2012-06-21
I'm sure this is unbelievably simple, but can anyone tell me how to use a variable to select a row in an excel macro.

e.g If I want to select rows 2 and 3 then I would write


What I want is to be able to replace the 2 and 3 with a and b (where a is 2 and b is 3).


Question by:StuartL
LVL 43

Accepted Solution

TimCottee earned 50 total points
ID: 6463438
Dim a As String
Dim b As String
a = "2"
b = "3"
Rows(a & ":" & b).Select

Author Comment

ID: 6463468
That works great, thanks.  I just couldn't find out the format of the (a&.. bit.



Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now