Listing multiple values in a single cell if they match

mwilburn01

New Member
Joined
Mar 27, 2014
Messages
1
Hello all,

I have a Gradebook where I enter the number of points a student earns per question on a test. The students names are in the first column and then their points follow. I have other columns such as total points, percentage, letter grade that follow but they are not part of my issue. I am simply looking for a way to list which problems they did not earn full credit on. First two Rows (after their name) list the question # and possible points. I have figured something out that kind of works but it is extremely long and I am sure there is a better way to do it.

Name1234567WHAT I AM LOOKING FOR
(Merged with above)2222334WOULD LOOK LIKE THIS
Sue20213242, 4, 6
Jimmy22222345
Sally10003001, 2, 3, 4, 6

<tbody>
</tbody>

Any help is much appreciated.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
mwilburn01,

Welcome to the MrExcel forum.

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


The below macro should work for a varying number of rows, and, columns.


Sample raw data:


Excel 2007
ABCDEFGHI
1Name1234567
2(Merged with above)2222334
3Sue2021324
4Jimmy2222234
5Sally1000300
6
Sheet1


After the macro:


Excel 2007
ABCDEFGHI
1Name1234567
2(Merged with above)2222334
3Sue20213242, 4, 6
4Jimmy22222345
5Sally10003001, 2, 3, 4, 6, 7
6
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub ReportNotFullCredit()
' hiker95, 03/27/2014, ME767407
Dim a As Variant, i As Long, c As Long
Dim lr As Long, lc As Long, s As String
lr = Cells(Rows.Count, 1).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column
a = Range(Cells(1, 1), Cells(lr, lc + 1))
For i = 3 To lr
  s = ""
  For c = 2 To lc
    If a(i, c) <> a(2, c) Then s = s & a(1, c) & ", "
  Next c
  If s <> "" Then
    If Right(s, 2) = ", " Then s = Left(s, Len(s) - 2)
    a(i, lc + 1) = s
  End If
Next i
Range(Cells(1, 1), Cells(lr, lc + 1)) = a
Range(Cells(3, lc + 1), Cells(lr, lc + 1)).HorizontalAlignment = xlLeft
Columns(lc + 1).AutoFit
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ReportNotFullCredit macro.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,234
Messages
6,123,776
Members
449,123
Latest member
StorageQueen24

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