excel vba columns and rows

Please see file that is attached - "EE-Not all values are copying to row 2.docx" for problem statement and workbook "EXX-0830-Column-Summary_v2.xlsm".
Who is Participating?
byundtConnect With a Mentor Commented:
You aren't seeing values in row 2 that are substrings of values already in your variable Spike. So if Spike already contains "Type 1B", the code won't add "Type 1".

Assuming that you want every unique value in the column to be added to row 2, then consider the following version of your sub Main. It surrounds each unique Cval in Spike with pipe characters |. The code can then test whether a new Cval (surrounded by pipe characters) is already in Spike. If not, then add it.
Sub Main()

    Dim Spike As String
    Dim Cval As String
    Dim C As Long
    Dim R As Long
    With ActiveSheet
        For C = 1 To LastColumn(4)
            Spike = "|"
            Cval = ""
            If .Cells(NwsTest, C).Interior.Color = RGB(220, 230, 241) Then
                For R = NwsFirstDataRow To LastRow(C)
                    Cval = Trim(.Cells(R, C).Value)
                    If Len(Cval) Then
                        If InStr(1, Spike, "|" & Cval & "|", vbTextCompare) = 0 Then
                            Spike = Spike & Cval & "|"
                        End If
                    End If
                Next R
                If Len(Spike) > 1 Then
                    Spike = Mid(Spike, 2, Len(Spike) - 2)   'Delete first & last characters
                    .Cells(NwsSum, C).Value = Replace(Spike, "|", ", " & vbCrLf)
                End If
            End If
        Next C
    End With
End Sub

Open in new window

tesla764Author Commented:
Fantastic. That works. Thank you so much.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.