ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with code about ranges (https://www.excelbanter.com/excel-programming/324562-problem-code-about-ranges.html)

cdb

Problem with code about ranges
 
I have the following code that is not acting as I was hoping it would:

Dim SelectedRange As Range, RangeCheck As Range

Set SelectedRange = Sheet1.Range("C2:C10")
SelectedRange.Select
For Each RangeCheck In SelectedRange
Range(RangeCheck).Select

When I use the SelectedRange.Select command it selects the correct command,
but when it gets to the Range(RangeCheck).Select is selects cell AR644
instead of the first cell in the given range.

What am I doing wrong??

Any help would be greatly appreciated.

cdb

KL

Problem with code about ranges
 
Hi cdb,

Try:

RangeCheck.Select

you don't need to do Range(RangeCheck) as RangeCheck is already a range and
not the name of the range (i.e.text string)

Regards,
KL

"cdb" wrote in message
...
I have the following code that is not acting as I was hoping it would:

Dim SelectedRange As Range, RangeCheck As Range

Set SelectedRange = Sheet1.Range("C2:C10")
SelectedRange.Select
For Each RangeCheck In SelectedRange
Range(RangeCheck).Select

When I use the SelectedRange.Select command it selects the correct
command,
but when it gets to the Range(RangeCheck).Select is selects cell AR644
instead of the first cell in the given range.

What am I doing wrong??

Any help would be greatly appreciated.

cdb




cdb

Problem with code about ranges
 
KL,

Works perfectly - thanks a lot.

cdb

"KL" wrote:

Hi cdb,

Try:

RangeCheck.Select

you don't need to do Range(RangeCheck) as RangeCheck is already a range and
not the name of the range (i.e.text string)

Regards,
KL

"cdb" wrote in message
...
I have the following code that is not acting as I was hoping it would:

Dim SelectedRange As Range, RangeCheck As Range

Set SelectedRange = Sheet1.Range("C2:C10")
SelectedRange.Select
For Each RangeCheck In SelectedRange
Range(RangeCheck).Select

When I use the SelectedRange.Select command it selects the correct
command,
but when it gets to the Range(RangeCheck).Select is selects cell AR644
instead of the first cell in the given range.

What am I doing wrong??

Any help would be greatly appreciated.

cdb






All times are GMT +1. The time now is 08:43 AM.

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