+ Reply to Thread
Results 1 to 3 of 3

text comparion in multiple workbooks

Hybrid View

  1. #1
    Registered User
    Join Date
    01-13-2010
    Location
    Oxford
    MS-Off Ver
    Excel 2010
    Posts
    57

    text comparion in multiple workbooks

    Hi Everyone

    I've scoured Google for an answer but because I don't know specifically how to word it I get lots of pages on using data validation instead of what I want

    What I'm looking for is a macro/command that will compare a list of column headers in one workbook which contains the same column headers as the 4 other workbooks to see if the column headers are in the same order and provide a summary report showing that they match

    so if workbook 1 has columns apple, banana, carrot, pear

    the report workbook would have have the same list and would show as yes, yes, yes, yes for the ones that match

    however if workbook 1 has columns apple, banana, pear, carrot

    the report workbook would have yes, yes, no, no as they are not in the same order anymore

    Ideally it would just show a final text box summary saying "All columns Match" or "Error - some columns do not match"

    Sounds complicated to someone like me and I've tried to figure out/learn the STRCOMP to see if it works but my skills are way below par. Happy to learn myself if anyone has a decent link to something similar

    Thanks for any and all help

    Dan_B

  2. #2
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: text comparion in multiple workbooks

    How far have you got regarding opening the workbooks you want to check?

    once you have got each one to open as needed all you need to do is get the 1st row of each one and compare it (assuming the first row contains the headers).

    Simple array would work for this so the first thing to do is get the order of the headers your going to compare against, if this was in a sheet (template sheet with the headers in there as needed) you can do

    
    Private GoodHeaders as variant
    
    Private Sub GetGoodHeaders()
        Dim Rng as Range
        Set Rng ThisWorkbook.Sheets("Template").UsedRange  'Get the entire block of data
        Set Rng = Rng.Rows(1)  'From the block just get the first row, the headers
        GoodHeaders = Rng.Value  'put the headers into an array, (#,#) 2 dimensional is what .Value gives you if you have more than 1 cell in the range, lets assume you do
    End Sub
    ok so now its just a matter of opening a workbook (just let me know if you need that part) and then looking through the sheets
    lets assume you just want to check sheet1, and the header row is always the first row of the block of data

    
    Private Function CheckWorkbookHeaders(WorkSheetToCheck as WorkSheet) as variant
    
        Dim Results() as boolean 'Keeping it simple we will just say whether we find good matches against the GoodHeaders and ignore results for anything else, for example if more columns are in the other worksheet we will just ignore them here.
        Dim i as integer
        Dim Rng as Range
        Dim HeadersToCheck as variant
        Dim HeaderCount as Integer
    
        Redim Results(lbound(GoodHeaders,2) to UBound(GoodHeaders,2) '1D Array to list the results, using the columns of the good header array to set the size
    
        Set Rng = WorkSheetToCheck.UsedRange
        Set Rng = Rng.Rows(1)
        HeadersToCheck = Rng.Value
    
        If IsArray(HeaderCount) then  'Remember if the range is only 1 cell this wont be an array it will just be a value
            HeaderCount = UBound(HeadersToCheck,2)
        Else
            HeaderCount = 1    
        End If
    
        For i = LBound(GoodHeaders,2) to UBound(GoodHeaders,2)   'Loop the good headers
                
            Select Case True
                Case HeaderCount = 1 AND i = 1    'If HeaderCount = 1 then its not an array and we need slightly different code too check
                     results(i) = (HeadersToCheck = GoodHeaders(1,i))
                Case HeaderCount < i AND i > 1  'If  we ran out of columns to check on the file we are checking then its not a match obviously
                     Results(i) = false
                Case Else  'the rest of cases are just normal checks, if true or false limited to the number of columns in the GoodHeaders array, Ignoring extra columns in the sheet we are checking
                     results(i) = (HeadersToCheck(1,i) = GoodHeaders(1,i))
            End Select
            
        Next i
        
        CheckWorkbookHeaders = Results 'return the results as a 1D array of true and false
    
    End Function
    ok so just a little something to look at, there are many ways to do it i just did it this way. just have a look through and if it makes sense just give it a try.

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: text comparion in multiple workbooks

    Actually, I can think of a way to do this without VB.

    Start with a blank sheet in either the master or separate workbook. Make links to the cells containing the header in the other workbooks. Then you can visually compare them, or set up formulas that evaluate to True / False and do a count of trues or falses for the overall status.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find Text String across Multiple Workbooks
    By craigos in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2013, 05:18 AM
  2. search for specified text in multiple workbooks
    By bharathiraja.tm in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2012, 07:08 AM
  3. a cell changing colour base on date comparion
    By mambo84 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2010, 02:59 AM
  4. Comparion one var with diff range
    By raviabburi in forum Excel General
    Replies: 7
    Last Post: 10-13-2009, 03:09 AM
  5. Data comparion by using pivot table
    By Eshwar_ng in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-30-2007, 10:00 AM
  6. [SOLVED] number comparion function
    By kysiow in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-10-2006, 12:39 AM
  7. [SOLVED] Multiple Workbooks Selection.text
    By mpeplow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2006, 07:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1