MovingCellContents

JohnGiacon

New Member
Joined
Mar 25, 2025
Messages
10
Office Version
  1. 365
Platform
  1. MacOS
Hi.
I have data in this form:
Play.xlsx
FG
510cat
6dog
711hat
812mat
9rug
10carpet
1113he
12they
Sheet1


And I would like it to end up in this form:
[the maximum number of Senses is 5]

Play.xlsx
BC
4IDSenses
5101. cat; 2. dog
6111. hat
7121. mat; 2. rug; 3. carpet
8131. he; 2. they
Sheet1


Ignore the row and column info.
Thanks, John
 
Here is my suggestion.
Click on the Range in Column F, Select Home/Find & Select, Go To Special, Choose blanks. Press = then press the up arrow and press control + Enter.
You can use
Excel Formula:
=UNIQUE(F5:F13)
to get the list of unique codes in the range (Adjust the formula to suit your range.)
Then assuming your data starts in B5, in Cell C5 use this formula:
Excel Formula:
=TEXTJOIN("; ",TRUE,IF(($F$5:$F$13=B5),$G$5:$G$13, ""))
Adjust the ranges according to your criteria.
 
Upvote 0
Another option, if range not an issue.
Book1
ABCDE
110catIDSenses
2dog101. cat; 2. dog
311hat111. hat
412mat121. mat; 2. rug; 3. carpet; 4. mug; 5. paper
5rug131. he; 2. they
6carpet
7mug
8paper
9water
1013he
11they
Sheet1

VBA Code:
Sub test(): Dim s, r&, i&, o&, a$, b$, c&: Set s = Sheets("Sheet1")
s.Range("D1") = "ID": s.Range("E1") = "Senses"
r = s.Cells(s.Rows.count, 2).End(3).Row: o = 2
For i = 1 To r
If s.Cells(i, 1) <> "" Then
If a <> "" Then s.Cells(o, 4) = a: s.Cells(o, 5) = b: o = o + 1
a = s.Cells(i, 1): c = 1: b = "1. " & s.Cells(i, 2)
ElseIf s.Cells(i, 2) <> "" And c < 5 Then
c = c + 1
b = b & "; " & CStr(c) & ". " & s.Cells(i, 2)
End If
Next: If a <> "" Then s.Cells(o, 4) = a: s.Cells(o, 5) = b
End Sub
 
Upvote 0
Solution
Here is my suggestion.
Click on the Range in Column F, Select Home/Find & Select, Go To Special, Choose blanks. Press = then press the up arrow and press control + Enter.
You can use
Excel Formula:
=UNIQUE(F5:F13)
to get the list of unique codes in the range (Adjust the formula to suit your range.)
Then assuming your data starts in B5, in Cell C5 use this formula:
Excel Formula:
=TEXTJOIN("; ",TRUE,IF(($F$5:$F$13=B5),$G$5:$G$13, ""))
Adjust the ranges according to your criteria.
Hi Dermie
Thanks for that; I will try it later - trying to get the job finished.
Best, John
Another option, if range not an issue.
Book1
ABCDE
110catIDSenses
2dog101. cat; 2. dog
311hat111. hat
412mat121. mat; 2. rug; 3. carpet; 4. mug; 5. paper
5rug131. he; 2. they
6carpet
7mug
8paper
9water
1013he
11they
Sheet1

VBA Code:
Sub test(): Dim s, r&, i&, o&, a$, b$, c&: Set s = Sheets("Sheet1")
s.Range("D1") = "ID": s.Range("E1") = "Senses"
r = s.Cells(s.Rows.count, 2).End(3).Row: o = 2
For i = 1 To r
If s.Cells(i, 1) <> "" Then
If a <> "" Then s.Cells(o, 4) = a: s.Cells(o, 5) = b: o = o + 1
a = s.Cells(i, 1): c = 1: b = "1. " & s.Cells(i, 2)
ElseIf s.Cells(i, 2) <> "" And c < 5 Then
c = c + 1
b = b & "; " & CStr(c) & ". " & s.Cells(i, 2)
End If
Next: If a <> "" Then s.Cells(o, 4) = a: s.Cells(o, 5) = b
End Sub
Thanks Sam, worked beautifully. Time I gave up trying to write vba, since there is such great help available.
Cheers, John
 
Upvote 0

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