+ Reply to Thread
Results 1 to 11 of 11

Compare Headers in Array - Display Missing Header - Ask and Rename

  1. #1
    Registered User
    Join Date
    09-09-2022
    Location
    Washington, DC area
    MS-Off Ver
    MS365
    Posts
    6

    Compare Headers in Array - Display Missing Header - Ask and Rename

    I have a project I am working on for myself. I have many parts of my macros complete. The attached spreadsheet only covers one part. The information below is also in the spreadsheet, but I am repeating it here, so folks can read it in the post without downloading the file.
    1. I get lists from a service with the information that I need
    2. There are two types of lists. Long Ones (LO) and Short Ones (SO). In my real-life data, SO has 13 headers and LO has 57
    3. I get 3 or more lists a week. I put all of the SO sheets into one Workbook and all of the LO sheets into another Workbook. - this part of a macro works fine -
    4. NOTE: All headers exist for each type of sheet, but they could be in random order
    5. My next step is to combine all of the worksheets into one master worksheet so I can upload them to my web service
    6. All the headers in the worksheets have the same names? I have found that the names might be COLUMN1 or misspelled instead of the intended column header and it might be in different column order. Any sheet could be slightly different. All headers should have the same name for the same data regardless of order
    7. I have a mix of sheets here because I don't know which active sheet will have which type of list when I open the files from a directory (not in this macro). What I have done so far. I created an array for the LO workbook and the SO workbook. Set the active worksheet in the workbook, then according to a count of header create an array for the sheet (SH) header. -All that works - THIS WORKBOOK
    8. "This is what I still need to do with the attached workbook.
      a. I want to compare the SH headers to the LO or SO headers
      b. Display which SH header is not in the LO or SO header Array
      c. Ask if I want to rename the SH header to the LO or SO header that was different from SH.
      d. Rename the Header
    9. Then I need to sort all of the columns and put them in the order that I want them. - I created that macro and that part works too.

    I have been at this entire process for a week now and just can't figure out the comparison approach and renaming. If there is a better way, let me know. I am trying to keep from having to do too much manually.

    Thanks in advance.
    Kehf
    Attached Files Attached Files
    Last edited by Kehfera; 09-09-2022 at 07:35 PM. Reason: adding sample workbook

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    Welcome to the forum.

    You are missing the SH sheet in the sample workbook.

    Your sample should show the before and end result.

  3. #3
    Registered User
    Join Date
    09-09-2022
    Location
    Washington, DC area
    MS-Off Ver
    MS365
    Posts
    6

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    The SH sheets are the two sheets in the workbook. I have created the other arrays manually within the macro. The sheets are where the headers are that I am trying to compare to the LO and SO arrays already defined in the macro.

    OH - Thanks for looking at this! It is greatly appreciated.
    Kehf

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    I don't quite follow your explanation so this may not help:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Ben Van Johnson

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    Kehfera,

    See if this is how you wanted.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-09-2022
    Location
    Washington, DC area
    MS-Off Ver
    MS365
    Posts
    6

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    This has come closest to my needs. I am still working out through DEBUG how this actually works. I got confused a bit with an error I got when I tried to rename the column. It is letting me know that the SO is missing headers that are not part of the SO array. I think what this is doing is comparing one sheet to the next when I think I need to compare the sheet headers to the array. Once I understand it, I might be able to tweak it and post it here if it works for me. I want to share the working solution.

    My explanation may not be so great but you followed it nicely. THANKS.

    Kehf

  7. #7
    Registered User
    Join Date
    09-09-2022
    Location
    Washington, DC area
    MS-Off Ver
    MS365
    Posts
    6

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    As I stepped through the solutions I think my explanation needs some clarification:

    I predefined the correct headers in my code.
    For Sheet SO I want the headers in the sheet to = the array headers in the code hedrSO
    For Sheet LO I want the headers in the sheet to = the array headers in the code hedrLO

    Here is my code stated in sentences.
    set the hedrSO = the headers I want for any SO sheet in the workbook
    set the hedrLO = the headers I want for any LO sheet in the workbook

    Go through all the sheets in the workbook
    Get the first sheet
    put the headers from the sheet into an array
    Can use the count of headers to determine if it is an LO sheet or an SO sheet
    if the headers are from and SO sheet then compare the hedrSO to the hedrSH (sheet header array)
    if there is a header missing (or misspelled-Nice to have) on the sheet show which header is missing and from which column, _
    then prompt to rename the column header on the sheet to the missing name
    end the middle if
    end the first if
    if the headers are from and LO sheet then compare the hedrLO to the hedrSH
    if there is a header missing (or misspelled-Nice to have) on the sheet show which header is missing and from which column, _
    then prompt to rename the column header on the sheet to the missing name
    end the middle if
    end the first if
    Get the next sheet
    Finished with all sheets

    I hope this clarifies the need a bit. Like I noted both sets of codes do a portion of the work but I am still trying to step through some of the code to understand where the fix may be needed.

    THANKS SO MUCH for everyone's help. I will post the solution when it works for me along with a better spreadsheet so everyone can learn.

    Kehf

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    Try
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-09-2022
    Location
    Washington, DC area
    MS-Off Ver
    MS365
    Posts
    6

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    I got the latest code from Jindon. I will work on it this evening. I stepped through it once and got an error in the sub "RenameHeader" when I went stepped through the code. It happened the second time around. The first time it was fine. Type mismatch. I am sure it is a small tweak and when I find it, I will post it.

    THANKS
    Kehf

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    Quote Originally Posted by Kehfera View Post
    I stepped through it once and got an error in the sub "RenameHeader" when I went stepped through the code. It happened the second time around.
    Not for me.
    Evidencing.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    09-09-2022
    Location
    Washington, DC area
    MS-Off Ver
    MS365
    Posts
    6

    Re: Compare Headers in Array - Display Missing Header - Ask and Rename

    Of course, I did not think that Jindon had errors in his code. It is definitely me and my code. I pasted in the code but something on my file kept it from working and I did not know enough to find the error and fix it. Since Jindon uploaded a file and I ran through it, it was perfect. However, I need to compare the headers in those two sheets to master headers. I will work on trying to integrate some code and get that part going. I will post it here.

    THANKS ALL! You have been so helpful. I wish I knew a bit more. Only time will help that and you all have helped me a bunch!

    Cheers,
    Kehf - I will post the code if I can get it to work the way I need it to.

+ 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. [SOLVED] Compare two columns on separate sheet, if missing, insert missing data
    By lilvictorians in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-03-2019, 11:44 PM
  2. autofilter method of range class failed -header has tables headers and non table headers
    By naveen.acheanz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-16-2016, 08:21 AM
  3. Replies: 3
    Last Post: 06-16-2016, 02:09 AM
  4. Similar headers exist but not able to remove/rename and keep correct header
    By PC2016 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-03-2016, 09:42 PM
  5. Replies: 2
    Last Post: 05-09-2012, 01:30 PM
  6. Finding a value in an array and display header
    By ryfy in forum Excel General
    Replies: 0
    Last Post: 07-27-2011, 11:41 AM
  7. Replies: 1
    Last Post: 04-02-2005, 01:06 AM

Tags for this Thread

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