?
Solved

Custom Excel lookup function (part 2)

Posted on 2014-01-15
6
Medium Priority
?
288 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

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.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

777 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