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".
EE-Not-all-values-are-copying-to.docx
EXX-0830-Column-Summary-v2.xlsm
tesla764Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

byundtMechanical EngineerCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tesla764Author Commented:
Fantastic. That works. Thank you so much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.