VBA for Remove & Concat

The_Rock

Board Regular
Joined
Jul 2, 2007
Messages
174
Hi Folks
I hope you can help with writing vba for the following.

I have 3 columns:

Location Oppt Status
UK1 JS001 Approved
UK1 JS002 Pending
NLD1 GS001 Approved
NLD1 GS002 Rejected
NLD1 GS003 Rejected

What I would like to do is go thru the first column, to make the 'Location' unique and then concat Oppty & Status, for example, using the above, the result should be:
Location Result
UK1 JS001 (Approved), JS002 (Pending)
NLD1 GS001 (Approved), GS002 (Rejected), GS003 (Rejected)

Hope you guys can help :-)
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You can use this .... If you data is in A, B and c column then it will show output at column M and N .. so can adjust this program as your data positioning

Dim lstRow, countRow, uniCounter, uniLstRow As Long
Dim flag As Integer
Dim strAddress As String
With ActiveSheet

.Range("M:N").ClearContents
lstRow = .Range("a65536").End(xlUp).Row

.Range("N1").Value = "Result"
.Range("M1:M" & lstRow).Value = .Range("A1:A" & lstRow).Value

.Range("M1:M" & lstRow).RemoveDuplicates Columns:=1, Header:=xlYes
uniLstRow = .Range("M65536").End(xlUp).Row
For uniCounter = 2 To uniLstRow

For countRow = 2 To lstRow

If .Range("M" & uniCounter).Value = .Range("A" & countRow).Value Then

If .Range("N" & uniCounter).Value <> "" Then
.Range("N" & uniCounter).Value = .Range("N" & uniCounter).Value & ", "
End If
.Range("N" & uniCounter).Value = .Range("N" & uniCounter).Value & .Range("B" & countRow).Value & " (" & .Range("C" & countRow).Value & ")"
End If


Next
Next


End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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