An UDF for Concatenate Function

Copper Contributor

Hello I was wondering whether it is possible to achieve this result using VBA/UDF?

 

Screenshot (219).png

 

Basically what I wanted to do is to be able to concatenate various string from different cell and achieve the shown result without typing the concatenate formula over and over but only one function with VBA/UDF, so we can get different kind of result based on the chosen cells

8 Replies

@aijatiw Yes, you can create a VBA function but my question is why complicate it that much?

 

You could easily just have a column C with the below formula:
="Student with name "&A2&" is now on year "&B2

HappyGoExcel_0-1698980137807.png

You can drag this formula down as many rows as you need. No need to be "typing the formula over & over again".

 

I'm sorry I think that I make myself unclear, because what I want is instead of typing =C35&C31&C36&D27, I want it to type =result(C31,D27) and it show the same result, so I was thinking how to put the "student with name " and "is now in year " like embedded on the sheet? I'm sorry if this confuses you I hope you get what I'm trying to say.

Because I need it to become as dynamic as possible. I will be dealing with more column and the result is not only to concatenate a row then drag it down,

@aijatiw Sure thing. I still wouldn't use VBA, you can just add two additional columns for your inputs:

HappyGoExcel_0-1698983919222.png

 

The formula will now be =C2&" "&A2&" "&D2&" "&B2

 

If you're really, really desperate for a VBA solution I could look into it but honestly it's overkill for a simple task as this.

Thank you for you dedication to my problem.

Maybe I need to elaborate more clearly what I am trying to achieve. Here is a new image

https://ibb.co/44tSnkk

I have this fruit, qty and a when column. Then, I will share this excel file to other people, What I want to do is that they can get different result based on what cells or combination that they like.

How to do that? And also the data for each column are fixed but the result should be vary.
No problems.

So it still sounds like the same solution as I mentioned in my first reply but it sounds like you want to add drop down lists where people can select which Fruit, Qty and When option - and then the result will be a combination of those 3?

If that's the case, you need to create Data Validation lists for those three and then link the result in the same way as in my first reply. Just Google how to create Data Validation lists in Excel.

If you're still stuck, let us know.

@aijatiw 

It looks like you have 365. A VBA/UDF solution is superfluous with Lambda as an option:

 

'Results Lambda
=LAMBDA(words,name,year,LET(word1, TAKE(words, 1), word2, TAKE(words, -1), word1 & " " & name & " " & word2 & " " & year))

Patrick2788_0-1699017216975.png

 

Cartesian_product?

 

Screenshot_2023-11-04-08-20-57-381_cn.uujian.browser.jpg

 

 select * from basic_Cartesian_product;

with a as(select f01 from basic_Cartesian_product where f01<>''),

b as (select f02 from basic_Cartesian_product where f02<>''),

c as(select f03 from basic_Cartesian_product where f03<>''),

d as (select f04 from basic_Cartesian_product where f04<>'')

select f01||' '||f03||f02||' '||f04 result from a,b,c,d;

 

 

 

 

f01 f02 f03 f04

student with nameis now on yearMike1
  Donna2
  Lula 
  Naomi 
  Luca 

result

student with name Mikeis now on year 1
student with name Mikeis now on year 2
student with name Donnais now on year 1
student with name Donnais now on year 2
student with name Lulais now on year 1
student with name Lulais now on year 2
student with name Naomiis now on year 1
student with name Naomiis now on year 2
student with name Lucais now on year 1
student with name Lucais now on year 2

 

 

@aijatiw 

I agree with @Patrick2788 that there is little point in introducing VBA as a programming environment when worksheet formulas are sufficient.  Now that dynamic arrays and recursion have made the worksheet formulas into a Turing complete language, that covers most computational tasks.

 

Another trick is to nest the Lambda functions to take two strings of parameters,

 

StudentYearλ
= LAMBDA(int, lnk, cls,
    LAMBDA(param1, param2, CONCATENATE(int, " ", param1, " ", lnk, " ", param2, " ", cls))
  )(intro, link, close)

 

This is still a Lambda function because only one parameter string is already provided.  That allows a worksheet formula to return the appropriate message for a list of students

= StudentYearλ(Name, Year)

From there it is easy to envision related formulas generated from the same core such as 

= StudentGradesλ(Name, Marks)

image.png