# Need to populate a cell with text value based on criteria

#### AndrewSDM

##### New Member
I've been having a great deal of trouble trying to figure out how to populate a cell with multiple text entries from certain criteria. I have information listed as such:

 UMID Box Number Format 1 1 16mm 2 1 16mm 3 1 8mm 4 2 16mm 5 2 35mm 6 2 3/4" Umatic 7 3 VHS 8 1 VHS 9 1 1/4" tape

<tbody>
</tbody>

I want to write a formula that will take this information from "Sheet 1" and populate cells in a "Sheet 2". I will need to populate cells with information such as "Number of items" per box and "Formats" in each box. I'm wanting formulas that will essentially help me get results like this:

 Box Number Number of items Media Types UMIDs 1 5 16mm, 8mm, VHS, 1/4"Tape 1,2,3,8,9 2 3 16mm, 35mm, 3/4"Umatic 4,5,6 3 1 VHS 7

<tbody>
</tbody>

I know that I can accomplish this with =COUNTIF(Sheet1!BoxNumber,1) for instance for counting the number of items within a box. Is there a better formula I could be using?

What I'm most concerned about is, How can I populate the cells in my "Mediatypes" and "UMIDs" columns like in the examples I've listed?

Thanks for any help!

### Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

##### MrExcel MVP
Sheet1, A:C, houses the data and Sheet2, A:D, the processing with A2 1, A3 2, and A3 3 the box numbers.

the following code as a module to your workbook usingAlt+F11...

Function aconcat(a As Variant, Optional sep As String = "") AsString
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function

and invoke on Sheet2...

B2, just enter and copy down:

=COUNTIF(Sheet1!\$B\$2:\$B\$10,A2)

C2, control+shift+enter, not just enter, and copy down:

=REPLACE(aconcat(IF(Sheet1!\$B\$2:\$B\$10=A2,", "&Sheet1!\$C\$2:\$C\$10,"")),1,2,"")

D2, control+shift+enter, not just enter, and copy down:

=REPLACE(aconcat(IF(Sheet1!\$B\$2:\$B\$10=A2,", "&Sheet1!\$A\$2:\$A\$10,"")),1,2,"")

#### Titian

##### Well-known Member

Thought I would try the Harlan Grove function as a learning exercise and believe that you woukd like to know that there is a problem in the function, first row, at the end, there is a space missing, it should read "As String" - so as it is, a copy and paste fails.

Hope that is helpful

##### MrExcel MVP

Thought I would try the Harlan Grove function as a learning exercise and believe that you woukd like to know that there is a problem in the function, first row, at the end, there is a space missing, it should read "As String" - so as it is, a copy and paste fails.

Hope that is helpful

I don't think there is anything wrong with it, unless my copy-and-paste action has failed. In case, the function directly from the workbook where I used it:

Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function

#### Titian

##### Well-known Member
Looks good this time
Regards

Replies
1
Views
285
Replies
3
Views
267
Replies
1
Views
243
Replies
4
Views
161
Replies
4
Views
275

1,195,682
Messages
6,011,134
Members
441,586
Latest member
rodsin76

### 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?

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