Solved

Excel formula help

Posted on 2011-09-02
12
301 Views
Last Modified: 2012-05-12
Hi,
How do you I say while logic in excel formula.
OR maybe ue array formula to achieve it.

Please have al ook at the attached spreadsheet.

On tab key I have a key and ref.
in Ref column I am using  -> IF(ISNA(VLOOKUP(A2,rngRef,2,FALSE)),"",VLOOKUP(A2,rngRef,2,FALSE))  
To get ref_src from RANGE -> rngRef on tab KeySrc
basically just mapping the keys and getting the corresponding ref

Please let me know irf its not clear. I am sure you will figure out quikcly by looking at the attached sheet

Now What I am trying to acheive is that
there are two rows/records with same key '123'
and I am trying to get Ref  and combination of Ref_src for the same key
in the from Ref_src, Ref_src
so for key = 123
Ref would look like a,b

It would be very helpful if some one could help me out in achieving this

thanks
0
Comment
Question by:SameerMirza
  • 6
  • 2
  • 2
  • +1
12 Comments
 

Author Comment

by:SameerMirza
ID: 36472798
0
 
LVL 23

Expert Comment

by:Eirman
ID: 36472803
> Please have a look at the attached spreadsheet.

There is no attachment
0
 
LVL 23

Expert Comment

by:Eirman
ID: 36472804
got it !!
0
 

Author Comment

by:SameerMirza
ID: 36472807
sorry just uploaded
0
 

Author Comment

by:SameerMirza
ID: 36473137
any luck Eirman?
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36473261
It's dificult to get the results in one cell with a formula (especially for more data which I asime you have) so how about the attached to get each Ref in a separate cell, i.e. in B2 paste this formula

=IF(COLUMNS($B2:B2)>COUNTIF(KeySrc!$A2:$A3,$A2),"",INDEX(KeySrc!$B2:$B3,SMALL(IF(KeySrc!$A2:$A3=$A2,ROW(KeySrc!$A2:$A3)-MIN(ROW(KeySrc!$A2:$A3))+1),COLUMNS($B2:B2))))

confirmed with CTRL+SHIFT+ENTER nad copied across - when matches are exhausted you get blanks, e.g. in your example the Ref 3 formula in D2 displays a blank, see attached

regards, barry
27288594.xls
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:c1nmo
ID: 36473303
Could be done easily in vba, possible workaround using formulas attached.
test1.xls
0
 

Author Comment

by:SameerMirza
ID: 36473398
c1nmo

I was wondering if it would be possible for you to provide me the VBA workaround for unlimited records.
0
 

Author Comment

by:SameerMirza
ID: 36473428
Barry,

it seems to work find for the existing records.
I was wondering if it owuld be possible for you write the one that would work for
multiple records.
may be using a range for the source
0
 
LVL 6

Accepted Solution

by:
c1nmo earned 300 total points
ID: 36473568
'\init
lKeyRow = 2
lSourceRow = 2

With Sheets("key")



'\loop through keys
Do
sKey = .Cells(lKeyRow, 1)

'\loop through source for matches

Do
sSource = Sheets("keysrc").Cells(lSourceRow, 1)
If sKey = sSource Then
sConcat = sConcat & Sheets("keysrc").Cells(lSourceRow, 2)
End If

lSourceRow = lSourceRow + 1
Loop While sSource <> ""

'\update key
.Cells(lKeyRow, 2) = sConcat

'\reset source vars
sConcat = ""
lSourceRow = 2

'\inc keyrow
lKeyRow = lKeyRow + 1

Loop While .Cells(lKeyRow, 1) <> ""


End With
0
 
LVL 50

Assisted Solution

by:barry houdini
barry houdini earned 200 total points
ID: 36473885
>I was wondering if it owuld be possible for you write the one that would work for
multiple records

Hello SameerMirza, the formula I suggested is easily extendable, e.g. changing all the A3 references to A50 we get this version

=IF(COLUMNS($B2:B2)>COUNTIF(KeySrc!$A2:$A50,$A2),"",INDEX(KeySrc!$B2:$B50,SMALL(IF(KeySrc!$A2:$A50=$A2,ROW(KeySrc!$A2:$A50)-MIN(ROW(KeySrc!$A2:$A50))+1),COLUMNS($B2:B2))))

copied across as before and down if necessary, see attached revised version

reagrds, barry
27288594v2.xls
0
 

Author Closing Comment

by:SameerMirza
ID: 36474145
Thanks alot guy.
Barry I am sure it would work for now I am happy with c1nmo's solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now