ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting a Range with a Variable in VB (https://www.excelbanter.com/excel-programming/383594-selecting-range-variable-vbulletin.html)

ClinicITguy1

Selecting a Range with a Variable in VB
 
Hello All,
I am trying to update a macro. I know that I can select an individual cell
using a variable by using the Cells property. I simply insert the variable
into the parameter as an index number for a row or column. However, if I
want to work with a range of cells, there is no way to pass a variable into
the Range property.

I'm sure this is a basic quesiton for you programmers out there. Can
someone please drop me a dime?


Jim Thomlinson

Selecting a Range with a Variable in VB
 
Not 100% sure what you are looking for but perhaps this is close...

range(Cells(1,1), cells(5,5)).select

--
HTH...

Jim Thomlinson


"ClinicITguy1" wrote:

Hello All,
I am trying to update a macro. I know that I can select an individual cell
using a variable by using the Cells property. I simply insert the variable
into the parameter as an index number for a row or column. However, if I
want to work with a range of cells, there is no way to pass a variable into
the Range property.

I'm sure this is a basic quesiton for you programmers out there. Can
someone please drop me a dime?


ClinicITguy1

Selecting a Range with a Variable in VB
 
Thanks.
I think I just had problems understanding how the parameters in the range
property functioned. The help documentation seemed to separate the
parameters with a colon, but then suggested that multiple sections be divided
by a comma. That was confusing.

The following table illustrates some A1-style references using the Range
property.

Reference Meaning
Range("A1") Cell A1
Range("A1:B5") Cells A1 through B5
Range("C5:D9,G9:H16") A multiple-area selection
Range("A:A") Column A
Range("1:1") Row 1
Range("A:C") Columns A through C
Range("1:5") Rows 1 through 5
Range("1:1,3:3,8:8") Rows 1, 3, and 8
Range("A:A,C:C,F:F") Columns A, C, and F


"Jim Thomlinson" wrote:

Not 100% sure what you are looking for but perhaps this is close...

range(Cells(1,1), cells(5,5)).select

--
HTH...

Jim Thomlinson


"ClinicITguy1" wrote:

Hello All,
I am trying to update a macro. I know that I can select an individual cell
using a variable by using the Cells property. I simply insert the variable
into the parameter as an index number for a row or column. However, if I
want to work with a range of cells, there is no way to pass a variable into
the Range property.

I'm sure this is a basic quesiton for you programmers out there. Can
someone please drop me a dime?


Jim Thomlinson

Selecting a Range with a Variable in VB
 
Range takes up to 2 arguments. The first argument is mandatory and the second
is optional. If only the first argument is specified then the range is made
up of whatever is specified in the first argument. If the optional second
argument is included the the range bounded by the upper left most cell and
lower right most cell of the 2 ranges will make a rectangular range of that
size.
--
HTH...

Jim Thomlinson


"ClinicITguy1" wrote:

Thanks.
I think I just had problems understanding how the parameters in the range
property functioned. The help documentation seemed to separate the
parameters with a colon, but then suggested that multiple sections be divided
by a comma. That was confusing.

The following table illustrates some A1-style references using the Range
property.

Reference Meaning
Range("A1") Cell A1
Range("A1:B5") Cells A1 through B5
Range("C5:D9,G9:H16") A multiple-area selection
Range("A:A") Column A
Range("1:1") Row 1
Range("A:C") Columns A through C
Range("1:5") Rows 1 through 5
Range("1:1,3:3,8:8") Rows 1, 3, and 8
Range("A:A,C:C,F:F") Columns A, C, and F


"Jim Thomlinson" wrote:

Not 100% sure what you are looking for but perhaps this is close...

range(Cells(1,1), cells(5,5)).select

--
HTH...

Jim Thomlinson


"ClinicITguy1" wrote:

Hello All,
I am trying to update a macro. I know that I can select an individual cell
using a variable by using the Cells property. I simply insert the variable
into the parameter as an index number for a row or column. However, if I
want to work with a range of cells, there is no way to pass a variable into
the Range property.

I'm sure this is a basic quesiton for you programmers out there. Can
someone please drop me a dime?



All times are GMT +1. The time now is 07:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com