+ Reply to Thread
Results 1 to 11 of 11

Msgbox if certain value exists in range

  1. #1
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Msgbox if certain value exists in range

    Hi all,

    It isn't probably to difficult, but i'm still a vba noob

    In column P of my sheet there are text values. Sometimes, for example the value could contain "test".
    If this is the case i would like that cell to be colored red, and also a msgbox that says "Test is found. It occurs amount of times" where it counts the amount of times it occurs also.

    Who wants to help me?

    Thanks!!!
    Last edited by Crispy85; 01-19-2016 at 08:16 AM.

  2. #2
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Re: Msgbox if certain value exists in range

    Firstly use conditional formatting, so use a formula in conditional formatting to say

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    then you can use the fill in the conditional formatting options to fill it red, you can then drag this down to the end of your column as long as you don't lock in the cell i.e $P$5

    For counting, there may be an easier way, but I would put a helper cell and use

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This will return how many times "Test" appears, from this answer you can then run a message box to display how many times it appears using the following, for example if your helper cell is Q1

    Please Login or Register  to view this content.
    To then run this crate a command button in excel under the developer tab, and place the code above in the command button, when you click the button the message box will display

  3. #3
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Msgbox if certain value exists in range

    Hi Shifty,

    Thanks you but i know how conditional formatting works, and also how the formulas work.
    However, i want it included in a vba script.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Msgbox if certain value exists in range

    Maybe:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Msgbox if certain value exists in range

    Hi John,

    Thanks!! i think this might actually work but my idea was that the cell text would be "this sentence contains test" and the script should search "test". Is it as simple as changing
    Please Login or Register  to view this content.
    ?

    So to be more clear.
    Test can be found as a value within a longer value. Like search "test" in "this cell has the word test". In this case the script should also color the cell and count it.
    Last edited by Crispy85; 01-19-2016 at 08:59 AM.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Msgbox if certain value exists in range

    Try:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Msgbox if certain value exists in range

    Hi John,

    Thanks! This is very strange.
    "test" is just because of that i don't want to use company information. But whenever i create a sample file with "test" the macro runs perfectly.
    However, if i put it in the final file. I use "cost" as a value and it only colors the first result red and at the and says "it occurs 0 times".

    Do you have an idea?

  8. #8
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Msgbox if certain value exists in range

    I attached a sample file for the word "cost".
    When i run it, it only counts 0 and only colors the first result.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Msgbox if certain value exists in range

    Try this. Note changes - 1) Moved code to a standard module vrs the Sheet1 module, 2) Added Option Compare Text at the top.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Msgbox if certain value exists in range

    Great John, Thanks!!

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Msgbox if certain value exists in range

    You're welcome. Glad to help out and thanks for the feedback.

+ 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 if value exists in range
    By JDG94 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-24-2015, 10:24 PM
  2. [SOLVED] How to determine if a range exists
    By plans in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-16-2014, 07:56 PM
  3. If cell value exists on textbox.value row, then display msgbox
    By Templemind in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-29-2014, 05:11 AM
  4. Replies: 2
    Last Post: 08-26-2014, 08:35 AM
  5. If named Range exists then, else next i
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2012, 11:42 PM
  6. Look if Value exists in range
    By Sniper in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-10-2009, 10:06 AM
  7. [SOLVED] See if a Range Name exists?
    By plh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2006, 05: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