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

,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:$65536,Xrows,ET))
Name: TheAZ
Refers To: =(INDEX(Sheet1!$1:$65536,2,AZ):INDEX(Sheet1!$1:$65536,Xrows,AZ))
Name: TheEL
Refers To: =(INDEX(Sheet1!$1:$65536,2,EL):INDEX(Sheet1!$1:$65536,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.