Aggregare string variables

cuubaa

New Member
Joined
Jul 4, 2008
Messages
8
Hi,
Here is my problem: I have 6 string variables, all of them with values from a finite (and short) list, so that very often there will be more than 2 variables with same value.
I need something like this:
Code:
sub agg(A as string, B as string, C as string, D as string, E as string, F as string) as string
agg("VV", "V9", "E1", "VV", "V9") = "VV - A, D; V9 - B, F; E1 - C"
I guess it should be simple but I just cannot get it right.
Thanks!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Not sure why you would want to do this in the first place but does this do what you want ?

Code:
Function Agg(a As String, b As String, c As String, d As String, e As String)
Dim xtest As Variant: xtest = Array(a, b, c, d, e)
Dim ytest As Variant: ytest = Array("", "", "", "", "")
Dim ztest As Variant: ztest = Array("A", "B", "C", "D", "E")
Dim y As Integer
Dim ans As String
For i = 0 To UBound(xtest)
    y = WorksheetFunction.Match(xtest(i), xtest, 0)
    If ytest(y) = "" Then
        ytest(y) = xtest(i) & " - " & ztest(i) & " "
    Else
        ytest(y) = ytest(y) & "," & ztest(i) & " "
    End If
Next i
For i = 0 To UBound(ytest)
    If ytest(i) <> "" Then ans = ans & ytest(i) & ";"
Next i
Agg = Left(ans, InStrRev(ans, " ") - 1)
End Function

ie

A1 = "VV", B1 = "V9", C1 = "E1", D1 = "VV", E1 = "V9"

F1 = Agg(A1,B1,C1,D1,E1) -> returns VV - A ,D ;V9 - B ,E ;E1 - C
 
Upvote 0
Yes, thank you lasw10 that is what I need.
I have a report that needs to be filled out automatically and I cannot rearrange nothing so the only way to fill out few cells (which are quite small) is to put them in one string, make it font size 7 and text wrap ;) Obviously this data is not of high importance, otherwise I would not agree for such way of presenting it, but it is there to meet traceability requirements found in different quality standards, so it will be only read if something goes really wrong ;)
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top