ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Refer to Ranges using Cells notation (https://www.excelbanter.com/excel-programming/333241-refer-ranges-using-cells-notation.html)

Scott P

Refer to Ranges using Cells notation
 
Hi,

I am trying to pass through a worksheet using VBA with a nested For loop and
would like to refer to the cells that I pass through using the Cells(row,
col) notation. Is there a way to refer to a range of cells (e.g. A1:A100)
using the Cells(row, col) notation instead of having to use the Range
notation?

Thanks in advance.

Alan Beban[_2_]

Refer to Ranges using Cells notation
 
There are several ways. One is

Set rng = Range("A1")
MsgBox Range(rng(1),rng(100)).Address

It will display $A$1:$A$100

Alan Beban

Scott P wrote:
Hi,

I am trying to pass through a worksheet using VBA with a nested For loop and
would like to refer to the cells that I pass through using the Cells(row,
col) notation. Is there a way to refer to a range of cells (e.g. A1:A100)
using the Cells(row, col) notation instead of having to use the Range
notation?

Thanks in advance.


Scott P

Refer to Ranges using Cells notation
 
I believe that I have found the answer to my own question, so I am posting it
here. It appears Excel allows you to refer to ranges of cells using the
"cells" notation using syntax such as this:

Set rng = Range(Cells(1, 1), Cells(1, 100))



"Scott P" wrote:

Hi,

I am trying to pass through a worksheet using VBA with a nested For loop and
would like to refer to the cells that I pass through using the Cells(row,
col) notation. Is there a way to refer to a range of cells (e.g. A1:A100)
using the Cells(row, col) notation instead of having to use the Range
notation?

Thanks in advance.


Tim Williams

Refer to Ranges using Cells notation
 
with activesheet
set rng = range(.cells(1,1),.cells(100,1))
'or
set rng = .cells(1,1).resize(100,1)
end with

Tim

"Scott P" wrote in message
...
Hi,

I am trying to pass through a worksheet using VBA with a nested For
loop and
would like to refer to the cells that I pass through using the
Cells(row,
col) notation. Is there a way to refer to a range of cells (e.g.
A1:A100)
using the Cells(row, col) notation instead of having to use the
Range
notation?

Thanks in advance.





All times are GMT +1. The time now is 03:03 PM.

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