ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop through single column of named range (https://www.excelbanter.com/excel-programming/372197-loop-through-single-column-named-range.html)

Andibevan

Loop through single column of named range
 
Hi,

I have a named range that covers A1:d4 - How do I loop through each cell in
Column C of the named range.

I know how to do it for a 'non-named' range but not for a named range

TIA

Andi



Jim Thomlinson

Loop through single column of named range
 
I would be inclined to use the intersect method something like this

dim rngToSearch as Range
dim rng as range

on error resume next
set rngtosearch = intersect(columns("C"), range("MyRange"))
on error goto 0

if rngtosearch is nothing then
msgbox "The range name changed and we have a problem."
else
for each rng in rngtosearch
msgbox rng.address
next rng
end if
--
HTH...

Jim Thomlinson


"Andibevan" wrote:

Hi,

I have a named range that covers A1:d4 - How do I loop through each cell in
Column C of the named range.

I know how to do it for a 'non-named' range but not for a named range

TIA

Andi




Dave Peterson

Loop through single column of named range
 
Dim myCell as range
dim myRng as range
set myrng = worksheets("somesheet").range("somename")
for each mycell in myrng.columns(3).cells
msgbox mycell.address '???
next mycell

There better be at least 3 columns in that range!


Andibevan wrote:

Hi,

I have a named range that covers A1:d4 - How do I loop through each cell in
Column C of the named range.

I know how to do it for a 'non-named' range but not for a named range

TIA

Andi


--

Dave Peterson

Andibevan

Loop through single column of named range
 
Thanks Dave - I was messing around with that idea but had missed the .cell
off the end of the statement

Ta muchly


"Dave Peterson" wrote in message
...
Dim myCell as range
dim myRng as range
set myrng = worksheets("somesheet").range("somename")
for each mycell in myrng.columns(3).cells
msgbox mycell.address '???
next mycell

There better be at least 3 columns in that range!


Andibevan wrote:

Hi,

I have a named range that covers A1:d4 - How do I loop through each cell

in
Column C of the named range.

I know how to do it for a 'non-named' range but not for a named range

TIA

Andi


--

Dave Peterson




Dave Peterson

Loop through single column of named range
 
It's not always required, but it never hurts (and it can be painful if you
needed it and didn't use it!).

Andibevan wrote:

Thanks Dave - I was messing around with that idea but had missed the .cell
off the end of the statement

Ta muchly

"Dave Peterson" wrote in message
...
Dim myCell as range
dim myRng as range
set myrng = worksheets("somesheet").range("somename")
for each mycell in myrng.columns(3).cells
msgbox mycell.address '???
next mycell

There better be at least 3 columns in that range!


Andibevan wrote:

Hi,

I have a named range that covers A1:d4 - How do I loop through each cell

in
Column C of the named range.

I know how to do it for a 'non-named' range but not for a named range

TIA

Andi


--

Dave Peterson


--

Dave Peterson


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

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