Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Named Range ..Offset?

Status
Not open for further replies.

Jagstrom

Technical User
Nov 13, 2008
18
US
have two named ranges "NameA" and "NameB"

When I loop though "A" and test for values how do I address the same row in "B"

Example

"NameA" "NameB"
1 text1
2 text2
3 text3

Something like:

For Each MyRange in Range("NameA")
if MyRange = 2 then
MyRange.Offset.Range("NameB") = "Changed text2"
next MyRange

I figure if use named ranges the end user can add and remove columns without breakn mycode



 
hi,
Code:
For Each MyRange in Range("NameA")
 if MyRange.value = 2 then 
    MyRange.Offset.(1,0).value = "Changed text2"  
 end if
next MyRange



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I believe the arguments of offset were transposed. Should be:
MyRange.Offset.(0,1).value = "Changed text2"
 
touche, ep! [blush]

My dyslexia is showing.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for your input,

I guess I could have explained that better but NameA and NameB are not in adjacent columns.

The Offset needs to be tied to the relative difference between the two ranges where ever they may be.

 
Code:
dim iOff as integer
iOff = Range("NameB").column - Range("NameA").columnn
For Each MyRange in Range("NameA")
 if MyRange.value = 2 then 
    MyRange.Offset.(0,iOff).value = "Changed text2"  
 end if
next MyRange


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Clever,

I should have seen that one.

Thanks, Skip

Jason
 
I should have seen that one."

After you begin to understand the Excel Object Model better, these things can become more readily apparent.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top