+ Reply to Thread
Results 1 to 3 of 3

Code to check if cells contain value

  1. #1
    Registered User
    Join Date
    03-13-2011
    Location
    Holland
    MS-Off Ver
    Excel 2007
    Posts
    45

    Code to check if cells contain value

    Dear users,

    I'm trying to write a code to check if cells in a specific row contain values. If they contain values the next sub will be played otherwise there will be a messagebox and it will exit the sub.

    Below a short version of the code i'm trying to write. in Column C from row 7 each cell has a text. Some cells contain the value 'New'.
    Somehow the code below doesnt work and I don't understand why. It should find the value New and if the value is found the messagebox will appear. But if this already wont work then there's no point for me in extending the code.

    Can anyone tell me what i'm doing wrong?
    Please Login or Register  to view this content.
    The code should look something like this
    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,631

    Re: Code to check if cells contain value

    Not easy to check without some test data ...

    The compare is case sensitive so "New" will not match "new" ... could be one problem.

    You also have a variable, "r", which you define and initialise but don't increment ... possibly another problem.

    If you're trying to compare cells on the same row as MyCell, you could use:

    Please Login or Register  to view this content.

    instead of:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Code to check if cells contain value

    Maybe something like

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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