+ Reply to Thread
Results 1 to 24 of 24

Column Comparision-Progressive scan and format cell

  1. #1
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Column Comparision-Progressive scan and format cell

    VBA Code / Macro for column comparison - progressive scan and formatting cell

    Data Range B3:V100 (Data type is DATE)

    Compare each cell in Column B with each cell in Column C, and each subsequent columns till Column V, (There could be a blank column also). The comparison and result should be -

    If the cell value, say is equal or +- 2 days, the target cell should be formatted as BOLD+Color, else do nothing

    So, the comparison would like

    B3 with C3, B3 with C4, B3 with C5, till last cell in column C, then
    B3 with D3, B3 with D4, B3 with D5, till last cell in column D, then
    B3 with E3, E4, E5, till last cell in Column E

    And so on till Column V

    Then

    B4 with C3, C4 and so on till last cell in Column C
    B4 with D3, D4, D5 and son till last cell in Column D, then
    B4 with E3, E4, E5, till last cell in Column E,

    And so on till Column V

    Then

    B5 with C3, C4 and so on till last cell in Column C
    B5 with D3, D4, D5 and son till last cell in Column D, then
    B5 with E3, E4, E5, till last cell in Column E,

    And so on till Column V

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    @nilem, Thanks for the feedback.

    When I run the macro, nothing happens.

    In my sample data - B3, the equal or +- 2 days are 16 Oct in Column C, 13 Oct in Column I


    Here is the sample file - http://www.mediafire.com/?926li1v6z633j35
    Last edited by analystbank; 10-07-2013 at 05:02 AM.

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    Please Login or Register  to view this content.
    note:
    15.10.2013 19:12:00 - 2 = 13.10.2013 19:12:00
    but 13.10.2013 00:00:00 < 13.10.2013 19:12:00 so cell I3 does not meet our criteria

  5. #5
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    You are right, that worked, but

    1) I've large data range having date format only, and changing them manually would be a nightmare, how do i reformat the cell as Date only, and no time.

    2) This macro would compare Column B with each subsequent column till Column V. What if i want to carry out same procedure, once above is done starting with Column C, and comparing each cell in subsequent column D to V, then, starting from Column D and comparing each cell in it with Column E till column V and so on till Last column comparison U with V only.

    Thanks
    Last edited by analystbank; 10-07-2013 at 05:57 AM.

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    "I've large data range having date format only, and changing them manually..."
    it is not necessary. Try
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    I could surely do Find and replace ' *' (space and asterix without quote) to remove the time element, that would be faster.


    SPLENDID, code at # 6 does the job. Nicely, Thanks, pal.

    Now, can u please help for part 2 only. The first part of the macro compares Each cell in Column B with Column C, D, E, and so on till Column V

    How nice, if code later compares (with same criteria) each cell from Column C with Column D, E, F and so on till V, then
    compares each cell from Column D with Column E, F, G, H and so on till V, then
    compares each cell from Column E with Column F, G, H, I and so on till V and lastly
    compares column U with Last column V only, and does the same thing

    P.S. : 1) Instead of Font color change, can we fill entire cell with color, in order to get attention easily
    2) Even if there is overwrite situation for column comparision, that would not be an issue.

    Thanks
    Last edited by analystbank; 10-07-2013 at 06:21 AM.

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    Pre-select any cell in column from B to V and run it
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    Yes, above works, but it removes the previously formatted cells, which i do not wish to disturb.

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    but what if the same cells will comply with the conditions for different columns?

  11. #11
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    it would have already been formatted earlier, and again if it gets formatted no issue.

    At the end, it is not important which cell in a given column is match against cells in other column.

    I just want to see the match dates per given criteria in each column at the end, regardless of its base.

    So, Macro in post # 6 is more good for me.

    So, alternatively, I was thinking to duplicate it by creating series of variables, and then start comparing Column C, then Column D and so on!!! (crude way to write code)
    Last edited by analystbank; 10-07-2013 at 07:12 AM.

  12. #12
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    take a look at post #8 and change this part of the code
    Please Login or Register  to view this content.
    for this
    Please Login or Register  to view this content.
    edited
    doubt it, but if you exactly follow your description,
    Please Login or Register  to view this content.
    Last edited by nilem; 10-07-2013 at 07:31 AM.

  13. #13
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    Done, Thank you very much. Macro in # 12, does the job as desired.

    How nice of you.

    Only one question, all being same, instead of starting with Column B, which line of the code, should be changed to what, if I want this analysis to be carried on starting from Column E.

    In your last modified code given in # 12

    Please Login or Register  to view this content.
    Last edited by analystbank; 10-07-2013 at 07:46 AM.

  14. #14
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    One more thing, just observed in my real workbook. I've header in Row 1, and Row2, and when i run macro ertert44, I get error message - RUN TIME ERROR 13, as TYPE MISMATCH

    at line
    Please Login or Register  to view this content.

  15. #15
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    try
    Please Login or Register  to view this content.
    and Bonus
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    not exactly

    I guess, the last solution in # 12 was giving the result, as desired, except that when I put text as Header in Row 1, and Row 2, it gives Type Mismatch Error.

    If I remove the text header, it gives the perfect solution.

    When I run macro given in #15, given as Bonus, I am not getting what's going on, as i feel, cell in Row 2 is being compared with others?

  17. #17
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    Here is the code from #12, which takes into account lines in the headers
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    Thank you very much nilem for your prompt replies.

    While I am keeping active cell as B2, and run this macro (ertert444), it formats certain blank cells too, and many other cells that meet the criteria remains un-formatted.

    Here is the file for your look - http://www.mediafire.com/?exnn8d07vaf1jp4

    P.s: pwd removed from file, apology. Sample data in Sheet9. In sheet9, macro named- ertert44_REV(), works, however, IT changes the color of all cells. I have different color in Header Row1 and 2 for specific reason. Is there any way to untouch Row 1, and 2, and Keep Data+format unchanged in Column A, on left hand side.
    Last edited by analystbank; 10-08-2013 at 01:06 AM.

  19. #19
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    "... I have different color in Header Row1 and 2 for specific reason..."
    Could you show an example of your file

  20. #20
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    Here is the data file. - http://www.mediafire.com/?cstgjcv380k0826

    Row 1, and Row 2 is used as Row Header, and Column A, ColumnB used as Column Header, so this should not be disturbed, data/format, either way.

    Real data is in range C3:V6, in some of the sheets, data range could be C3:V50, but it will always begin from C3, where the comparison and formatting should be made using vba code.

  21. #21
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    I hope now everything right (see attachment)
    Attached Files Attached Files

  22. #22
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    When i click on above link, i get message that, I dont have permission to access this page

  23. #23
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Column Comparision-Progressive scan and format cell

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: Column Comparision-Progressive scan and format cell

    Thanks, this works. On this very same subject, can i ask for some more alternates, after few days or whenever you are comfortable.?

    I think, the alternate, is not very tricky, as the main solution you have very well managed to find.

    Thank you, very much for your precise, prompt solution, SIR.

    The alternate scenario would be -

    Perform same process but when we start from Column E, it should compare in alternate column till Column V

    i.e. Start with Column E, skip column F, and compare each cell in Column G with same criteria, and then Column I, (skip Column H) then Column K (skip column J) and so on and color cell in given color,

    then start from Column G (skip Column F) and compare in alternate subsequent columns.....

    Once this is done,
    It should start from Column F, skip Column G, and compare with H, skip Column I, and compare with K and so on. and give different color.

    So now, the comparison is in alternate columns from left to right

    Good if this could be done, else, I will continue with solution given in #23 above.

    File and data would be same.
    Last edited by analystbank; 10-08-2013 at 02:39 AM.

+ 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. Multiple Column Data Comparision and Output
    By nostra in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-07-2013, 12:07 AM
  2. Macro to scan column and copy corresponding cell
    By RobbieMoulton in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2011, 12:12 AM
  3. Excel 2007 : column comparision trouble
    By colman in forum Excel General
    Replies: 1
    Last Post: 06-02-2011, 05:57 PM
  4. Single column data comparision chart
    By goels in forum Excel General
    Replies: 3
    Last Post: 05-31-2011, 04:52 AM
  5. Column Comparision
    By dayaptl in forum Excel General
    Replies: 3
    Last Post: 11-27-2006, 10:10 PM

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