Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA for intersection of two named ranges


I'm sorry. The answer has got to be out here somewhere, but I feel lik
I am beating my head against the floor.

A one sheet workbook.

Four named vertical ranges of 50 items each (Lets pretend each of th
four range names is a plant types).

50 named horizontal ranges of 4 items each (each range name is a
letter state abbreviations).

For simplicity, let's say that the resultant table is of the word
"No", "Poor","Good" "Great".

The user selects a state and a "plant" from two validation set dro
down lists. The workbook change event is triggered, and there goes th
code to determine the word or value in the cell that is at th
intersection of the two, let's say again for simplicity "MI" an
"Banana Tree", which would probably result in a "NO".

I can write the names of the ranges separated by a space after an = i
a cell and easily get the result, but I sure can't figure out how t
transfer the result of two drop-down boxes into same formula (at leas
not so it works), and all the more worse to do so via VBA. I would LOV
to be able to do so both ways, but just one would save me. Please hel
before my head explodes

--
brucem
-----------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...fo&userid=3287
View this thread: http://www.excelforum.com/showthread.php?threadid=52875

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default VBA for intersection of two named ranges

Haven't we all beat our heads.

Are you using dropdown boxes on the sheet, or in a user created form?

I like creating vba forms with OK & Cancel buttons and list boxes and drop
down combos, you know.

Let me know if this would help.

"brucemc" wrote:


I'm sorry. The answer has got to be out here somewhere, but I feel like
I am beating my head against the floor.

A one sheet workbook.

Four named vertical ranges of 50 items each (Lets pretend each of the
four range names is a plant types).

50 named horizontal ranges of 4 items each (each range name is a 2
letter state abbreviations).

For simplicity, let's say that the resultant table is of the words
"No", "Poor","Good" "Great".

The user selects a state and a "plant" from two validation set drop
down lists. The workbook change event is triggered, and there goes the
code to determine the word or value in the cell that is at the
intersection of the two, let's say again for simplicity "MI" and
"Banana Tree", which would probably result in a "NO".

I can write the names of the ranges separated by a space after an = in
a cell and easily get the result, but I sure can't figure out how to
transfer the result of two drop-down boxes into same formula (at least
not so it works), and all the more worse to do so via VBA. I would LOVE
to be able to do so both ways, but just one would save me. Please help
before my head explodes.


--
brucemc
------------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871
View this thread: http://www.excelforum.com/showthread...hreadid=528753


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA for intersection of two named ranges


Just right there on the sheet, trying to make it as simple as possible
If I only made it more complicated I could pretend that there was goo
reason for me not being able to do something that should be s
simple..

--
brucem
-----------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...fo&userid=3287
View this thread: http://www.excelforum.com/showthread.php?threadid=52875

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default VBA for intersection of two named ranges

This is my interpretation of your request:

Where cells G1 and H1 have the dropdown lists. The code selects the cell
instead of returning the value. Change to suit:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, cc As Range

Set c = Me.Range("G1")
Set cc = Me.Range("H1")
If Intersect(Target, Union(c, cc)) Is Nothing Then Exit Sub
If IsEmpty(c) Or IsEmpty(cc) Then Exit Sub
On Error Resume Next
Intersect(Range(c.Value), Range(cc.Value)).Select
On Error GoTo 0
End Sub

Regards,
Greg


"brucemc" wrote:


I'm sorry. The answer has got to be out here somewhere, but I feel like
I am beating my head against the floor.

A one sheet workbook.

Four named vertical ranges of 50 items each (Lets pretend each of the
four range names is a plant types).

50 named horizontal ranges of 4 items each (each range name is a 2
letter state abbreviations).

For simplicity, let's say that the resultant table is of the words
"No", "Poor","Good" "Great".

The user selects a state and a "plant" from two validation set drop
down lists. The workbook change event is triggered, and there goes the
code to determine the word or value in the cell that is at the
intersection of the two, let's say again for simplicity "MI" and
"Banana Tree", which would probably result in a "NO".

I can write the names of the ranges separated by a space after an = in
a cell and easily get the result, but I sure can't figure out how to
transfer the result of two drop-down boxes into same formula (at least
not so it works), and all the more worse to do so via VBA. I would LOVE
to be able to do so both ways, but just one would save me. Please help
before my head explodes.


--
brucemc
------------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871
View this thread: http://www.excelforum.com/showthread...hreadid=528753


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default VBA for intersection of two named ranges

Worksheetfunction version that returns the cell value of the intersection:

Where cells G1 and H1 have the dropdown lists.

=INDEX(INDIRECT(H1), ROW(INDIRECT(G1)))

Regards,
Greg


"brucemc" wrote:


I'm sorry. The answer has got to be out here somewhere, but I feel like
I am beating my head against the floor.

A one sheet workbook.

Four named vertical ranges of 50 items each (Lets pretend each of the
four range names is a plant types).

50 named horizontal ranges of 4 items each (each range name is a 2
letter state abbreviations).

For simplicity, let's say that the resultant table is of the words
"No", "Poor","Good" "Great".

The user selects a state and a "plant" from two validation set drop
down lists. The workbook change event is triggered, and there goes the
code to determine the word or value in the cell that is at the
intersection of the two, let's say again for simplicity "MI" and
"Banana Tree", which would probably result in a "NO".

I can write the names of the ranges separated by a space after an = in
a cell and easily get the result, but I sure can't figure out how to
transfer the result of two drop-down boxes into same formula (at least
not so it works), and all the more worse to do so via VBA. I would LOVE
to be able to do so both ways, but just one would save me. Please help
before my head explodes.


--
brucemc
------------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871
View this thread: http://www.excelforum.com/showthread...hreadid=528753




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default VBA for intersection of two named ranges

I forgot to point out that you need to subtract an offset if the vertical
ranges don't start in the first row. The function would have been better
stated as:

Where OS is the row number of the top of the vertical ranges.

=INDEX(INDIRECT(H1), ROW(INDIRECT(G1)) - OS)

Regards,
Greg

"Greg Wilson" wrote:

Worksheetfunction version that returns the cell value of the intersection:

Where cells G1 and H1 have the dropdown lists.

=INDEX(INDIRECT(H1), ROW(INDIRECT(G1)))

Regards,
Greg


"brucemc" wrote:


I'm sorry. The answer has got to be out here somewhere, but I feel like
I am beating my head against the floor.

A one sheet workbook.

Four named vertical ranges of 50 items each (Lets pretend each of the
four range names is a plant types).

50 named horizontal ranges of 4 items each (each range name is a 2
letter state abbreviations).

For simplicity, let's say that the resultant table is of the words
"No", "Poor","Good" "Great".

The user selects a state and a "plant" from two validation set drop
down lists. The workbook change event is triggered, and there goes the
code to determine the word or value in the cell that is at the
intersection of the two, let's say again for simplicity "MI" and
"Banana Tree", which would probably result in a "NO".

I can write the names of the ranges separated by a space after an = in
a cell and easily get the result, but I sure can't figure out how to
transfer the result of two drop-down boxes into same formula (at least
not so it works), and all the more worse to do so via VBA. I would LOVE
to be able to do so both ways, but just one would save me. Please help
before my head explodes.


--
brucemc
------------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871
View this thread: http://www.excelforum.com/showthread...hreadid=528753


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA for intersection of two named ranges


Thank-you very much, this looks like it should work, if only I can fix
whatever I have done wrong:

In my working VBA with Access I regularly used the ME. reference, but
now with Excel it is not recognizing it for some reason and I have to
change it to Worksheets(1). - Any idea what would cause this? (Office
2003)

Though the code runs fine (without errors prior to introducing
"Indirect" and changing ME to WorkSheets(1)), it does not select the
cell - thoughts?

I am getting an undefined variable for INDIRECT - any thoughts on the
cause of this too?


--
brucemc
------------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871
View this thread: http://www.excelforum.com/showthread...hreadid=528753

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default VBA for intersection of two named ranges

Point 1:-
The Me reference should work if you put the code in the worksheet code
module (e.g. Sheet1(Sheet1)) instead of a standard module. I have it working
at my end. Granted, this is all in accordance with my interpretation of your
situation. I may have it wrong.

Point 2:-
There is no reference to "INDIRECT" in my VBA version. The INDIRECT
worksheet function is contained in the worksheet fucntion (wf) that I
intended to be entered in a worksheet cell. I do use "Intersect" however.
Possibly, you may have to qualify it as:

Application.Intersect

There are two references in the code. Try changing both.

Point 3:-
I had both the VBA code and the wf working provided the row offset issue is
accounted for. As usual, I blew the post re the wf version. OS should be the
row number of the top of the vertical ranges - 1. If the vertical ranges
start in row 5 then OS should be 4. You don't need it if they start in the
first row.

Point 4:-
The vertical range dropdown is assumed to be in G1 and the horizontal range
dropdown in H1. You may have to reverse these in the code and wf.

Regards,
Greg

"brucemc" wrote:


Thank-you very much, this looks like it should work, if only I can fix
whatever I have done wrong:

In my working VBA with Access I regularly used the ME. reference, but
now with Excel it is not recognizing it for some reason and I have to
change it to Worksheets(1). - Any idea what would cause this? (Office
2003)

Though the code runs fine (without errors prior to introducing
"Indirect" and changing ME to WorkSheets(1)), it does not select the
cell - thoughts?

I am getting an undefined variable for INDIRECT - any thoughts on the
cause of this too?


--
brucemc
------------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871
View this thread: http://www.excelforum.com/showthread...hreadid=528753


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA for intersection of two named ranges


Great THANKS! With a little adjusting it works, and works very well.


--
brucemc
------------------------------------------------------------------------
brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871
View this thread: http://www.excelforum.com/showthread...hreadid=528753

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
intersection of named ranges Dave B[_9_] Excel Programming 4 December 15th 05 10:42 PM
I NEED A FUNCTION TO FIND IF THERE IS AN INTERSECTION BETWEEN 2 DATE RANGES MissSara Excel Worksheet Functions 10 September 7th 05 09:40 PM
I NEED A FUNCTION TO FIND IF THERE IS AN INTERSECTION BETWEEN 2 DATE RANGES MissSara Excel Programming 10 September 7th 05 09:40 PM
Like 123, allow named ranges, and print named ranges WP Excel Discussion (Misc queries) 1 April 8th 05 06:07 PM
Use intersection of column and TWO ranges in formula? Ed Excel Programming 2 January 12th 05 02:39 PM


All times are GMT +1. The time now is 06:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"