Jon Peltier question: use of MATCH
John laid it out for you.
What you are missing is
Insert=Name=Define.
This doesn't involve a macro. It is done in Excel itself.
--
Regards,
Tom Ogilvy
"Bryan Kelly" wrote in message
.. .
That is rather odd. The example came from selecting F1 with the "Match"
selected. The window is titled "Microsoft Excel Visual Basic." It seems
that one should assume that the example will work for visual basic. Oh
well.
But on to the next level. I now have:
ET_column = Application.Match("Elapsed Time", Range("A1:Z1"), 0)
AZ_column = Application.Match("Elapsed Time", Range("A1:Z1"), 0)
EL_column = Application.Match("Elapsed Time", Range("A1:Z1"), 0)
Range("ET_column, AZ_column, EL_column").Select
My goal is to write a macro that will make a chart based on the names in
the
top row of the columns. When I record a macro to make a chart, one of
the
lines is:
Range("C:C,D:D,E:E").Select
But this MATCH function returns a single digit such as 3. How can I use
this to build a chart using a macro?
Jon Peltier made a suggestion something more than a week ago about using a
Define Name function. I looked up "define" and "name" and it had no such
entry. If I use this define name operation, can I have a macro to give to
a
customer that will work for them?
Here is what Jon said.
You can do this with dynamic ranges. Assuming your labels are in row 1
of Sheet1, here are some defined names that construct the X and Y values
for your chart. Press CTRL+F3 to open the Defined Name dialog, and
define these names:
Name: ET
Refers To: =MATCH("Elapsed Time",Sheet1!$1:$1,0)
Name: AZ
Refers To: =MATCH("AZ",Sheet1!$1:$1,0)
Name: EL
Refers To: =MATCH("EL",Sheet1!$1:$1,0)
(ET, AZ, and EL are the column numbers where these labels are found.)
Name: Xrows
Refers To:
=COUNT(INDEX(Sheet1!$1:$65536,1,ET):INDEX(Sheet1!$ 1:$65536,65536,ET))
(This is the number of rows used in the Elapsed Time column)
Name: TheX
Refers To:
=(INDEX(Sheet1!$1:$65536,2,ET):INDEX(Sheet1!$1:$65 536,Xrows,ET))
Name: TheAZ
Refers To:
=(INDEX(Sheet1!$1:$65536,2,AZ):INDEX(Sheet1!$1:$65 536,Xrows,AZ))
Name: TheEL
Refers To:
=(INDEX(Sheet1!$1:$65536,2,EL):INDEX(Sheet1!$1:$65 536,Xrows,EL))
(These are the data ranges under the labels.)
Now use the chart wizard to create a chart. In step 2, click on the
Series tab, Select or Add the first series, name it "AZ", and enter
=Sheet1!theX in the X Values box and =Sheet1!theAZ in the Y Values box.
Add the second series, again enter =Sheet1!theX in the X Values box, and
enter =Sheet1!theEL in the Y Values box. No matter which column has the
particular labels (and the left to right alignment doesn't matter), the
dynamic ranges will find the appropriate data for the chart.
"Norman Jones" wrote in message
...
Hi Bryan,
test_variable = MATCH(39000,B2:B8,1)
Try,
test_variable = Application.Match(39000, Range("B2:B8"), 1)
In Excel you can refer to the range as B2:B8, but in VBA you need to
explicitly use a range object and enclose the A1-style address between
quotes.
---
Regards,
Norman
"Bryan Kelly" wrote in message
...
I am trying to use the match command. From the Excel help file I
built
this
line of code
test_variable = MATCH(39000,B2:B8,1)
I added "test_variable =" to what I copied from the Excell file.
Excel does not like the colon between the B2 and B8 saying it wants a
separator.
The line from Jon's original note was
Name: ET
Refers To: =MATCH("Elapsed Time",Sheet1!$1:$1,0)
Excel doesn't like either one. How do I get this match to work?
--
Bryan Kelly
Time is the medium we use to express out priorities.
|