1
votes

I am a little stuck at the moment. I am working on an array of data and need to find a way to input column numbers into formulas.

-I have used the match function to find the corresponding column number for a value.
ex. "XYZ" matched with Column 3, which is equivalent to C1:Cxxxxxx

-now for inputing the C1:Cxxxxxx into a formula to get data for that particular column, I would like to be able to directly reference the Column 3 part, because I plan on using this workbook in the future and the column needed to run the calculation may or may not be column 3 the next time I use it.
- is there any way to tell excel to use a formula to tell excel which column to use for an equation?

so a little more detail, I have the equation

=AND(Sheet3!$C$1:$C$250000=$A$4,Sheet3!$B$1:$B$250000=$B$4)

instead of specifying to use column C, is there a way to use a formula to tell it to use C?

EDIT: more additional info; "i am basically running the equivalent of a SQL where statement where foo and bar are true, I want excel to spit out a concatenated list of all baz values where foo and bar are true. ideally i would like it to ONLY return baz values that are true, then I will concat them together separately. the way I got it now, the expression will test every row separately to see if true; if there is 18K rows, there will be 18K separate tests.. it works, but it's not too clean. the goal is to have as much automated as possible. *i do not want to have to go in and change the column references every time I add a new data arra*y"

Thanks

2
Have you tried using the COLUMN function? - acfrancis
yes, column will just return the column value (a number). I want to be able to use that value in another formula to replace Sheet3!$C$1:$C$250000, in other words it will be automated so i will not have to change it every time. - user2989981
i will give a little more background; i am basically running the equivalent of a SQL where statement where foo and bar are true, I want excel to spit out a concatenated list of all baz values where foo and bar are true. ideally i would like it to ONLY return baz values that are true, then I will concat them together separately. the way I got it now, the expression will test every row separately to see if true; if there is 18K rows, there will be 18K separate tests.. it works, but it's not too clean - user2989981

2 Answers

1
votes

You can use INDEX, e.g. if you have 26 possible columns from A to Z then this formula will give you your column C range (which you can use in another formula)

=INDEX(Sheet3!$A$1:$Z$250000,0,3)

The 0 indicates that you want the whole column, the 3 indicates which column. If you want the 3 can be generated by another formula like a MATCH function

Note: be careful with AND in

=AND(Sheet3!$C$1:$C$250000=$A$4,Sheet3!$B$1:$B$250000=$B$4)

AND only returns a single result not an array, if you want an array you might need to use * like this

=(Sheet3!$C$1:$C$250000=$A$4)*(Sheet3!$B$1:$B$250000=$B$4)

1
votes

You could use ADDRESS to generate the text, you then need to use INDIRECT as you are passing a string rather than a range to the fomula

=AND(INDIRECT(ADDRESS(1,3,,,"Sheet3") & ":" & ADDRESS(250000,3))=$A$4 ,INDIRECT(ADDRESS(1,2,,,"Sheet3") & ":" & ADDRESS(250000,2))=$B$4)

Obviously replace the 3s and 2s in the ADDRESS formulae with your MATCH function you used to get the column number. The above assumes the column for $B$1:$B$25000 is also found using `MATCH', otherwise it is just:

=AND(INDIRECT(ADDRESS(1,3,,,"Sheet3") & ":" & ADDRESS(250000,3))=$A$4 ,Sheet3!$B$1:$B$25000=$B$4)

Note a couple of things:

  1. You only need to use "Sheet3" on the first part of the INDRECT
  2. Conditions 3 and 4 in the ADDRESS formula are left as default, this means they return absolute ($C$1) reference and are A1 style as opposed to R1C1

EDIT

Given the additional info maybe using an advanced filter would get you near to what you want. Good tutorial here. Set it up according to the tutorial to familiarise yourself with it and then you can use some basic code to set it up automatically when you drop in a new dataset:

Paste in the dataset and then use VBA to get the range the dataset uses then apply the filter with something like:

Range("A6:F480").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _ Sheets("Sheet1").Range("A1:B3"), Unique:=False

You can also copy the results into a new table, though this has to be in the same sheet as the original data. My suggestion would be paste you data into hidden columns to the left and put space for your criteria in rows 1:5 of the visible columns and then have a button that gets the used range for your data, applies the filter and copies the data below the criteria:

Range("A6:F480").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets _ Range("H1:M3"), CopyToRange:=Range("H6"), Unique:=False

Button would need to clear the destination cells first etc, make sure you have enough hidden columns etc but it's all possible. Hope this helps.