Computing.Net > Forums > Office Software > Find Common Values in All Columns

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Find Common Values in All Columns

Reply to Message Icon

Name: kkjellquist
Date: April 2, 2009 at 09:18:16 Pacific
OS: Windows XP
Subcategory: Microsoft Office
Comment:

I have a spreadsheet with 42 (A thru AP) columns of text values. Some values appears in all 42 columns, while most appear in some, but not all. Is there a macro that will scan the columns for values that appear in all 42 columns & place it in the 43rd (AQ)column?

I found a few threads that dealth with filtering, but I don't think that will work.



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: April 2, 2009 at 13:57:22 Pacific
Reply:

re: Is there a macro that will....

There is now!

Sub FindCommonValues()
'Loop through 42 columns
 For col = 1 To 42
'Find last cell with data in each column
  lastRow = Cells(Rows.Count, col).End(xlUp).Row
'Loop through each value in column
   For Each myVal In Range(Cells(1, col), Cells(lastRow, col))
'Reset Found counter
    foundCount = 0
'Search all columns for value
     For srchCol = 1 To 42
      With Columns(srchCol)
       Set c = .Find(myVal, lookat:=xlWhole)
'Increment counter each time value is found
        If Not c Is Nothing Then foundCount = foundCount + 1
       End With
     Next
'If 42 values are found, value is in every column
   If foundCount = 42 Then
'Make sure value hasn't already been listed
      lastAQrow = Cells(Rows.Count, "AQ").End(xlUp).Row
       With Range("AQ1:AQ" & lastAQrow)
        Set c = .Find(myVal)
         If c Is Nothing Then
'If it's not already there, put value in next cell
          nxtVal = nxtVal + 1
          Range("AQ" & nxtVal) = myVal
         End If
        End With
     End If
'Loop for next value
   Next
'Loop for next column
 Next
End Sub


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Find Common Values in All Columns

Finding closest value in an array www.computing.net/answers/office/finding-closest-value-in-an-array/5528.html

Finding negative numbers in excel www.computing.net/answers/office/finding-negative-numbers-in-excel/2555.html

Excel Formula help www.computing.net/answers/office/excel-formula-help/7958.html