+ Reply to Thread
Results 1 to 17 of 17

Format if not found in addition to found

  1. #1
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Format if not found in addition to found

    I am using this code to search several worksheets against a master inventory list. Works pretty good, but there are 2 issues with it.

    First, I would like it to format yellow for a good match and red for no match. Currently the yellow for match works nicely.

    Also, I am just copy and pasting the find and do part of the code for each worksheet. Is there a simpler way to do this?
    I will be searching some 16 worksheets with it.


    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    Hi, I am assuming you are reasonably confident and just need some pointers:

    1. To loop through all the worksheets you can use
    Please Login or Register  to view this content.
    If there are any sheets you want t ignore then a case statement works well eg
    Please Login or Register  to view this content.

    If you want to find the colours in the colorindex select a cell on a blank sheet and run this

    Please Login or Register  to view this content.
    Then just before your For Each v In ws3.Range("B2:k100") you could set the interior colour for the whole range to your other colour
    Last edited by tony h; 02-02-2016 at 07:08 PM.


    click on the * Add Reputation if this was useful or entertaining.

  3. #3
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: Format if not found in addition to found

    Reasonably confident? Not really, but I learn better when I can take these answers and try to figure them out without a blind copy and pastes.

    That being said, changing the interior color ahead of time, then only changing the ones found worked well.
    I have two concerns with that method though
    - There is a large amount of non valuable text, headings, misc numbers, etc that I would rather have left alone.
    - I would eventually like to make a list of the numbers not found. My thought here was to write a separate sub to find all cells with the interior color matching the cells not found.

    So an argument to highlight the cells not found would serve more purposes in the long run.

    The "For Each ws" code worked really good on a simpler sub in which I cleared the contents of all but 3 sheets.
    But I am having trouble understanding how to insert it into the code above. Here is a shorter version with just the ws2 sheet being looked in.

    Please Login or Register  to view this content.

    I'll keep tinkering with it. I am just googling different codes and trying to understand the syntax. I have a long way to go.

  4. #4
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    We might get there

    As a start I have just tidied up a few things in your last sample code.

    I got rid of the with and end withs as they weren't doing anything.
    It was got to see the variables declared with Dim statements. I have included the types in the declarations - this will help in various ways but you will notice the intellisense being more helpful.

    The question I need you to explain better is how to define the "not found"

    The


    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: Format if not found in addition to found

    Awesome, every line helps.

    The INVMaster List is compiled by our server wide inventory system. It is supposed to be what we are accountable to have stocked.
    This list is copy and pasted onto the worksheet.

    The BI2C sheets and the subsequent 18 or so other sheets contain what we have physically inventoried.

    (Somewhat unrelated, these sheets are populated by a "All Warehouses" sheet that contains a 2D map of the warehouses and each product in its given location. I have a subscript that scans that sheet and then lists the products by category on these physical inventory sheets.)

    So the immediate goal here is to have excel highlight cells that contain values that are on the INVMaster sheet AND ALSO the other physical inventory sheets one color, say Yellow, and then the values that are found ONLY on the INVMaster sheets and not the physical inv sheets a separate color, say Red.


    And eventually I would like to have a separate sub that would generate a list of the values that are in Red. This is why I was looking for a different code to label those values.



    If it would be significantly helpful I could put together a mock sheet that resembles what I am working with and post it. I just have to change some of the entry data for company privacy etc.

  6. #6
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    ok there are lots of ways to approach this.
    I suggest
    loop through all the possible cells in the floorplan ie Worksheets("INVMaster").Range("A1:A5000"). and determine whether this is a stock location. Question : How do you know it is a stock location? eg is it that the cell contains text?

    Then for each stock location: loop through the other worksheets and test the equivalent cell and test it to see if it has a value and then colour this cell appropriately.



    Does that seem about right to you

  7. #7
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: Format if not found in addition to found

    Here is a cleaned up version of what I am working with.

    Some names and details have been changed, but the only significant change is that there are only two physical inv sheets instead of 18.

    The location is simply for our reference and doesn't involve any formulas etc.

    We are checking the INVMaster list against what we say is physically here.


    Maybe this will clarify my questions a bit.

    Thanks!
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    That has given me an idea. I'll send something over later.

  9. #9
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    I have put a button on the start page.

    The way I have tackled the problem was to put the invmaster data and the other sheet data into a new workbook (it could have been new sheets in the same workbook)

    I have left the formulae in so that it is easier to follow.

    APROBLEM in the sample data on the invmaster sheet the data on the rows varies a bit. I assume this was just a problem with the sample.

    Hope this gives you some ideas
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: Format if not found in addition to found

    Sorry for the delay, this isn't by any means my full time job.

    I am a Supervisor and this is a solution to a problem, but one of many I'm afraid.



    Thanks for the different perspective, it gives me another way to look at these types of things.



    One question, on the sheet generated you have the line

    Please Login or Register  to view this content.
    Why would it be labled not found when it was found?


    This sheet would ideally be used by a handful of people in our facility, some of which may not be excel masters. My goal is to make a sheet that is extremely user friendly. Generating a new sheet on top of what is already present may just be enough to scare off someone who is new to excel.


    But overall every example of code helps me problem solve my way through and I genuinely say thank you for your time and effort.

    I will store this aside for the time being, I am met with the challenge of having something perfect, or having something at all.
    A more important function I am going to be working on next is reversing the check color function and having it search the individual product sheets as well.


    I will use your same principle of making them all red, then highlight yellow if found, but honestly its going to be a bit of a challenge for me to get the code reversed.


    Highlighting if not found is a nice feature I will come back to later, but I need to prioritize my functions for the time being.

  11. #11
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    Good luck with everything.

    There is an inconsistency with your data on the sheet InvMaster and I just bodged together some code that corrects for some of the scenarios. The line with the Not found is a scenario that hasn't been catered for.
    I had hoped it was just inconsistent on the sample data rather than "real life". If it is real-life then this section will need to be a bit more clever. If it is just the sample then this section is easy.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: Format if not found in addition to found

    What inconsistencies?

    Seemed to work ok with my codes. Just not with the functionality I was hoping for.

  13. #13
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    A small example of the inconsistency which shows the data not lining up. I have replaced the spaces with x to make it clearer

    9BHR50002xxxxxxx5BI2Cxxxxxxxxxxxxxxxx50833xxxxxxxx1333.000
    9BHR50002xxxxxxx5BI2Cxxxxxxxxxxxxxxxx50979xxxxxxxx1433.000
    9BHR50002xxxxxxx5BI2Cxxxxxxxxxxxxxxxx50981xxxxxxxx1100.000
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx------------
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4583.000
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx============

    9BWR2xxxxxxxxxxx2BW2Cxxxxxxxxx48525xxxxxxxxx236.000
    9BWR2xxxxxxxxxxx2BW2Cxxxxxxxxx48727xxxxxxxxx303.000
    9BWR2xxxxxxxxxxx2BW2Cxxxxxxxxx49009xxxxxxxxx268.000
    9BWR2xxxxxxxxxx2BW2Cxxxxxxxxx49475xxxxxxxxx288.000
    9BWR2xxxxxxxxxxx2BW2Cxxxxxxxxx49640xxxxxxxxx936.000
    9BWR2xxxxxxxxxxx2BW2Cxxxxxxxxx49769xxxxxxxxx418.000
    9BWR2xxxxxxxxxxx2BW2Cxxxxxxxxx50159xxxxxxxxx204.000


    ... occurring between lines 49 to 59
    There is an obvious difference between the top block and the lower block but also occurances such as the line with 288.000.
    There are various more oddities I the rest of the data.
    Last edited by tony h; 02-16-2016 at 03:17 PM.

  14. #14
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: Format if not found in addition to found

    Ah yes.....that is actually exactly it will be in real life.

    This is a copy and pasted report from our computer inventory program.

    Not much I can do to make it all line up without making this process no longer a time saver

  15. #15
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    Quote Originally Posted by cwhite86 View Post
    Ah yes.....that is actually exactly it will be in real life.

    This is a copy and pasted report from our computer inventory program.

    Not much I can do to make it all line up without making this process no longer a time saver
    Ah. In that case the portion of code I listed in post #11 just needs to take account of the different formats. By being generous with the mid statements and wrapping them in a trim would solve a lot of the issues eg =trim(mid(A1,12,10))

  16. #16
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: Format if not found in addition to found

    I have never used a trim before.


    So when you put in Case 51 and Case 52 this was to compensate for the different lengths of the useless data in the cell?

    So then we would need more mid statements to compensate for the variety? We would thus create more Cases?


    Are we creating a fixed case for each possible scenario?

    Cell A1 for example may not always be trimmed at the same amount.
    I would rather not rewrite each case everytime.

    Thanks for your patience

  17. #17
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Format if not found in addition to found

    trim removes spaces from the beginning and end of a string. So the following all result in just ABC

    trim("ABC")
    trim(" ABC ")
    trim(mid("123 ABC ",5,6))


    So for the lines following mid statements based on the I will trim() to the same values

    9BWR2xxxxIxxxxxxx2BW2CxxxxxIxxxx49009xxxxIxxxxx268.000
    9BWR2xxxxIxxxxxx2BW2CxxxxxxIxxx49475xxxxxIxxxx288.000
    9BWR2xxxxIxxxxxxx2BW2CxxxxxIxxxx49640xxxxIxxxxx936.000

    But for the following you might want different case statements as the last columns might overlap (but you will know whether this is the case

    9BHR50002xxxxxxx5BI2Cxxxxxxxxxxxxxxxx50981xxxxxxxx1100.000
    9BWR2xxxxxxxxxxx2BW2Cxxxxxxxxx48525xxxxxxxxx236.000

+ 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. Search for value in a range and overwrite if found and create new if not found
    By mm671750 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-04-2016, 01:19 PM
  2. [SOLVED] Way to Format row if certain text is found in a column.
    By bdouglas1011 in forum Excel Programming / VBA / Macros
    Replies: 74
    Last Post: 11-02-2014, 11:24 PM
  3. Replies: 3
    Last Post: 03-04-2014, 04:55 AM
  4. IF Webpagecontent FOUND then X IF Webpage content NOT FOUND THEN Y
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-01-2013, 02:57 PM
  5. Check for values in a table and if found add value found in column to left to list
    By robhargreaves in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-07-2013, 02:57 PM
  6. Replies: 3
    Last Post: 05-15-2013, 12:16 AM
  7. [SOLVED] Message (in one window) for each file found/not found
    By kboy1289 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-08-2013, 04:03 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