×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Excel Ranges in VBA: Reference same row of NamedRange2 based on current location within NamedRange1

Excel Ranges in VBA: Reference same row of NamedRange2 based on current location within NamedRange1

Excel Ranges in VBA: Reference same row of NamedRange2 based on current location within NamedRange1

(OP)
I must be forgetting something, but I figured I'd post online to see if any of you hear can clear the mud off my eyes.

For a process used by various Excel files, I want to say something like:

When they update a cell within Range1, a query runs, populating various cells. A new item I'm adding is WAY to the right, and I do not want to use the .Offset() structure to get there, but would rather name the range for Range2 (further right 1 column).

The data will look something like the below image:


It doesn't seem to me like using Range.Intersect nor Range.Offset would work.

How do I basically say, When the Target range (ActiveCell) is in Range1(3) or Range1, row 3, then update the value in Range2(3) or Range2, row 3?

Please embarrass me and show me what simple item I'm forgetting.

Thanks

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

RE: Excel Ranges in VBA: Reference same row of NamedRange2 based on current location within NamedRange1

Hi,

You could use the Worksheet_Change Event.

CODE

If Not Intersect(Target, Range1) Is Nothing Then
   Cells(Target.Row, Range2.Column).Value = KJV1611Value
End If 
...assuming that Range1 and Range2 are defined as range objects as in a Structured Table (of course a ST would need some extra window dressing code)

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Excel Ranges in VBA: Reference same row of NamedRange2 based on current location within NamedRange1

(OP)
Yes, that's EXACTLY how I need to do this.

The data is not in a table object, but it is structured in basic column/row table design. So yes, it'll work in that method perfectly well.

I think I did consider that option at one point, but must have been when I had stepped away and forgot to test it or similar out.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

RE: Excel Ranges in VBA: Reference same row of NamedRange2 based on current location within NamedRange1

And, yes, Intersect can work as well...

CODE

Intersect(Target.EntireRow, Range2.EntireColumn).Value = KVJ1611Value 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Excel Ranges in VBA: Reference same row of NamedRange2 based on current location within NamedRange1

(OP)
That's pretty cool! Never thought of using Intersect that way. To date, I've only really used it to say "is RangeX within NamedRangeY?"

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close