Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Custom Excel lookup function (part 2)

Posted on 2014-01-15
6
Medium Priority
?
296 Views
Last Modified: 2014-01-16
follow-up to http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28339566.html#a39784131

If i wanted to return more than one column (the join range), eg to concatenate a few columns, would this be possible with a simple variation?
0
Comment
Question by:xenium
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 24

Expert Comment

by:Steve
ID: 39784628
OK, the attached file has the following formula:

Function lookupjoin(SearchValue As Variant, SearchRange As Range, JoinRange As Range, wordSeperator As String, Optional LineSeperator As String)

Dim x As Long, y As Long, z As Long
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim colArr
Dim JoinString As String

z = JoinRange.Columns.Count
ReDim colArr(1 To z)

For x = 1 To SearchRange.Count
    If SearchRange(x, 1) = SearchValue Then
       For y = 1 To z
            colArr(y) = JoinRange(x, y)
       Next y
       JoinString = Join(colArr, wordSeperator)
       If Not d.exists(JoinString) Then
            d.Add JoinString, ""
       End If
    
    End If
Next x

If LineSeperator = Empty Then LineSeperator = vbCrLf
lookupjoin = Join(d.keys, LineSeperator)

End Function

Open in new window


This will allow for a Range to be concatenated.
It does have the optional second line joiner (set to default to crlf).
It should be quite apparent how it works from the examples in the workbook.
Any questions let me know.
Example.xlsm
0
 

Author Comment

by:xenium
ID: 39785654
Works great thanks! Simple question (i hope) how can I enter a discontiguous JoinRange, eg if i want to return columns B and D for example.

Cheers
0
 
LVL 24

Expert Comment

by:Steve
ID: 39785808
That is not as simple as you would hope, you could add a variable for columns to include/exclude.
But passing a group of ranges is not so easy as they get separated by commas which ruins the formula.
How many columns need to be joined? Do they change?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:xenium
ID: 39785834
Maybe 3 or 4 columns. They probably won't change. Solution needs to be fairly user-friendly as I won't be doing the updates to rows etc, and user will just copy-paste formulae down etc.
0
 
LVL 24

Accepted Solution

by:
Steve earned 1120 total points
ID: 39786043
OK the attached has a change to allow for selecting the columns as a set of numbers...

so for columns 1 and 3 you would enter 13.
for columns 1 and 2 and 3 use 123.

Have a look and see if it is better.

Have hard coded the spaces and line feeds as this may be better in the code.

ATB
Steve.
Example.xlsm
0
 

Author Closing Comment

by:xenium
ID: 39787024
Works great thanks again!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

610 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