VBA to Concat multiple columns based on multiple criteria

OscarBlack

New Member
Joined
Apr 27, 2022
Messages
6
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi, this is my first time so I apologize for mistakes.

I have already looked all over internet and have not manage to find an answer to fit my question.

I have this set of data on sheet1

1651097564166.png



And I want to concatenate the IDs, Targets and DNS based on Name and Risk on Sheet2 like this
So if it has the same name eg: "Generic IWP" and different risks to categorize it differently
But if it has the same name eg: "Traceroute" and same risks to concat it as it shows.

1651098045033.png
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
HELP me please!
I would think that at least one of the reasons it has taken so long for somebody to reply is that helpers have no easy sample data to test with, since we cannot copy/paste from your images into our Excel.
For the future, I suggest that you investigate XL2BB

See if this helps (in your 2019 version).

OscarBlack.xlsm
ABCHI
1IDTargetDNSNameRisk
211.1.1.1N/AaInfo
321.1.1.2example.combHigh
431.1.1.2N/AaInfo
Sheet1



OscarBlack.xlsm
BCDG
1RiskNameIDsTargets
2Highb2"example.com" (IP:1.1.1.2)
3Infoa1, 3"N/A" (IP:1.1.1.1), "N/A" (IP:1.1.1.2)
Sheet2
Cell Formulas
RangeFormula
D2:D3D2=TEXTJOIN(", ",1,IF(Sheet1!H$2:H$10=C2,IF(Sheet1!I$2:I$10=B2,Sheet1!A$2:A$10,""),""))
G2:G3G2=TEXTJOIN(", ",1,IF(Sheet1!H$2:H$10=C2,IF(Sheet1!I$2:I$10=B2,""""&Sheet1!C$2:C$10&""" (IP:"&Sheet1!B$2:B$10&")",""),""))
 
Upvote 0
Hello and thank you for your reply. Unfortunately I could not, due to strict regulations of security and privacy. Adding an untrusted plugin breaks company policy.
I have tried your formulas which unfortunately dont work. I was looking something on vba as the data is a lot and it would take formulas ages to load.
Thank you for your time and trying to help me.
 
Upvote 0
Unfortunately I could not, due to strict regulations of security and privacy. Adding an untrusted plugin breaks company policy.
In that case you could consider copy/paste small sections from your worksheet directly into your post and identify the rows/columns like below. At least something we can copy.

Row/ColBCD
1​
RiskNameIDs
2​
Highb2
3​
Infoa1, 3

I have tried your formulas which unfortunately dont work.
As you can see from my sheet it worked for me (at least as I understand the question). In what way did it not work for you?
- Error value?
- Wrong answer?
- Right answer in wrong place?
- Excel crashed?
- Something else?
 
Upvote 0
No Error or any prompt. I put the formulas exactly as it is and press calculate but nothing happens.
I have tested them on new excel with the exact names and data but no error or indication.
I am on excel 2019, double checked just to be sure.

I am attaching another example below based on your input that hopefully can give a better inside of what i am trying to achieve.

On Sheet1 I have this data:

ABCHI
IDIPHOSTNAMERISK
11.1.1.1example.comREDInfo
21.1.1.1example.comBLUEInfo
31.1.1.1example.comBLUEInfo
41.1.1.2example2.comREDCritical
51.1.1.3example3.comREDHigh
61.1.1.4example4.comREDMedium


And i want to produce this on Sheet2

BCDEG
RISKNAMEIDNAME & IDIP & HOST
InfoBLUE2,3BLUE (ID: 2, 3)"example.com" (IP: 1.1.1.1),"example.com" (IP: 1.1.1.1)
CriticalRED4RED (ID: 4)"example2.com" (IP: 1.1.1.2)
HighRED5RED (ID: 5)"example3.com" (IP: 1.1.1.3)
MediumRED6RED (ID: 6)"example4.com" (IP: 1.1.1.4)
InfoRED1RED (ID: 1)"example.com" (IP: 1.1.1.1)


Compares and list all unique names with the Risk associated and concat the name with ID of column E and IP and host on column G
For example ID 2 and 3 on Sheet 1 have the same name and same risk so it will add them together but IDs 1,4,5,6 have same name but different risk so it will list them separately.
To clarify Sheet 2 is completely empty, there is no data all data is on Sheet1.
 
Upvote 0
To clarify Sheet 2 is completely empty,
That was not clear at the beginning (to me at least). Your question was ..
And I want to concatenate the IDs, Targets and DNS based on Name and Risk
To me, that sounded like Name and Risk were available and you wanted help only with the concatenation of ID, Target & DNS.

If you are wanting to produce everything on Sheet2 then I think that you are going to need a vba approach. I'm afraid that I don't have sufficient time to look at that approach at the moment.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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