+ Reply to Thread
Results 1 to 6 of 6

Test Cell for contents

  1. #1
    Forum Contributor
    Join Date
    04-23-2015
    Location
    UK
    MS-Off Ver
    Office Pro Plus 2021
    Posts
    120

    Test Cell for contents

    Hi,

    K2 holds a formula that returns an integer/number.

    I would like to test as follows (pseudo code):

    If Cells("K2") ..... Is Numeric And > 7 'Then do one thing (1)
    ElseIf IsNumeric And < 7 ' 'Then do something else (2)
    Else There's something very wrong, so start to panic ! (3)

    Basically 1 will be the expected situation, and 2 is a realistic possibility, but rare
    3 should not ever be the case.

    There is one other test:
    If user has deleted the formula but then inserted their own number.
    That too would be a problem, so a test for the formula would be good.

    Regards and thanks.

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Test Cell for contents

    Maybe this helps:
    Please Login or Register  to view this content.
    Last edited by berlan; 05-12-2015 at 02:02 PM. Reason: minor change

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

    Re: Test Cell for contents

    Maybe:

    Please Login or Register  to view this content.
    Although I don't see how (3) could ever be the case?

  4. #4
    Forum Contributor
    Join Date
    04-23-2015
    Location
    UK
    MS-Off Ver
    Office Pro Plus 2021
    Posts
    120

    Re: Test Cell for contents

    Thanks to you both.

    Since this check is running in Event code, I think it'll be best to put the Select Case construct into a Function ?, then call the appropriate procedure from there.

    Good/bad idea?

    Thanks again.
    (and I really should have remembered Select Case).

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

    Re: Test Cell for contents

    I use Select Case in event code all the time?

  6. #6
    Forum Contributor
    Join Date
    04-23-2015
    Location
    UK
    MS-Off Ver
    Office Pro Plus 2021
    Posts
    120

    Re: Test Cell for contents

    Thanks John,

    I had seen advice that best practice was to keep all Event subs limited to deciding which procedures to run.
    This permits the same Event to be used for different purposes.

    That was why I questioned whether a Function was appropriate.

    Regards and thanks.

+ 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. Replies: 3
    Last Post: 08-21-2013, 07:10 PM
  2. IF statement to test the contents of a cell
    By Dowsey1977 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-21-2010, 12:44 PM
  3. How to test cell contents in a macro?
    By JennyGard in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2006, 11:08 AM
  4. Is there a logical test for a cell's format instead of contents
    By Bruce in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-16-2005, 09:45 PM
  5. Test is cell contents are a URL
    By Jim in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2005, 02:06 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