Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

use cell contents as

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Use Cell Contents As Function Array

Use Cell Contents As Function Array

ResolvedVersion 2010

Frank has attended:
Excel VBA Intro Intermediate course
Excel VBA Advanced course

Use Cell Contents As Function Array

Hello,

I have a problem which I feel cannot be solved without some complex vba.

I am creating a flexible template to quickly run some basic comparisons across multiple fields with the minimum amount of user manipulation.

I have used the formula below to return the address of a unique range (which there will be many)....

=ADDRESS(MATCH(B11,'Sheet 2'!B:B,0),3,1,1,"Sheet 2")&":"&ADDRESS(LOOKUP(2,1/(Dynamic Named Range=B11),ROW(Dynamic Named Range)),3,1,1)

I have changed some labels for confidentiality purposes.

But imagine cells B1:B10 on Sheet 2 contain the word "Dog". Cell B11 on the active sheet where the formula exits also contains the word "Dog". The Dynamic Named Range refers to text in Column B on Sheet 2. The result is something like...

'Sheet 2'!$C$1:$C$10

Now I have my unique range, the problem is using it without having to manually copy and paste into a function's syntax.

The function I am using is a modified version of the Nth_Occurrence function, the VBA code can be found on Google. The syntax works like this:
Nth_Occurrence(range, lookup value, occurence, row offset, col offset). I am looking for a piece of data, based on a value looked up within the unique range which may or may not occur more than once.

The VBA for the function has been modified from the popular code found on Google to ensure that say for an example a value only occurs twice within a range. If you attempt to find the third occurrence an error value is returned, where as before the function looped back to the beginning of the range to find a third occurrence.

Right so the problem here is, how do I use the contents of the formula first used, to return the unique range, in the Nth_Occurrence function? I have attempted so many different array formulas to no avail. I think the solution may lie in using one of the many old Excel formulas I have not used before to create a particular type of named range.

My method is fine for looking up one value. But data may be dropped into the sheet resulting in there being 100+ unique values each with it's own corresponding unique range. Requiring the user to copy and paste the initial formula appropriately to create all the unique ranges, then paste these ranges into each Nth_Occurrence function, results in no time being saved and opens up the possibility of user error.

For any forum moderators viewing this request, please advise if you would like to see some example data, leave your email and I will contact you. Any thoughts on the matter would be greatly appreciated.

RE: Use Cell Contents As Function Array

Hi Frank, thanks for your query. Your particular problem is too specific for me to reply with an actual formula answer, but it strikes me you might possibly be able to concatenate the references together as text strings and then turn those references into actual references using the INDIRECT function.

http://www.excelforum.com/excel-worksheet-functions/635150-convert-text-to-formula.html

http://www.cpearson.com/excel/indirect.htm

See how you get on.

Anthony

RE: Use Cell Contents As Function Array

Unfortuantely we had tried utilising the INDIRECT function before making the post to no avail.

Thanks for the try anyway!

RE: Use Cell Contents As Function Array

In which case, if you have a developer handy, tell them to loop through the cells using variables to concatenate the relevant references, then write them back to the cells as formulae. Failing that come on our code course and I'll show you how to do it!

All the best,

Anthony

RE: Use Cell Contents As Function Array

Actually Anthony after some time away from this sheet I feel there may be a far easier way to solve my problem, using the sumif anf indirect function this is very close to working.

So using the Address and lookup formula concatenated, I have my range refenence, so for example...

=ADDRESS(MATCH($B11,'US PRO CSV Import'!$B:$B,0),3,1,1,"US PRO CSV Import")&":"&ADDRESS(LOOKUP(2,1/(US_PRO_WorkTitle=$B11),ROW(US_PRO_WorkTitle)),3,1,1)

Gives a result, the range- 'US PRO CSV Import'!$C$2:$C$8

Increasing the column number gives the sum range - 'US PRO CSV Import'!$F$2:$F$8

Now if I put these range references into a sumif formula, I can get the result I need, no problem. However the issue is, copying and pasting these ranges, for hundreds of unique values (located in B11:..let's say "B'X'" if you get my meaning) would take an incredibly long time.

I have used several variation on a SUMIF/INDIRECT combnation to no avail, for example...

=SUMIF(INDIRECT(ADDRESS(13,14)),"Criteria Reference",INDIRECT(ADDRESS(14,14)))

This assumes I have copied and pasted the results of the address formula, as values into N13 and N14.

I have also tried...

=SUMIF(INDIRECT("I"&K11),"Criterria Reference",INDIRECT("J"&K11))

This assumes that K11 contanis a number, the row number needed to extract the value from, in this example I11 and J11, the range references for the SUMIF formula.

When using the SUMIf and INDIRECT function I get an answer of '0', which is incorrect. I have a feeling the error I am making is in how I am using the INDIRECT function to reference the ranges neesed for the SUMIF formula. I think this can be solves without a VBA answer.

Any ideas?

Fri 16 Mar 2012: Automatically marked as resolved.

Excel tip:

Add a € to your cells

If you need to add a € symbol to your Excel sheet - hold down the key Alt Gr and 4.

Alt Gr is located on the right side of the space bar.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.