+ Reply to Thread
Results 1 to 3 of 3

[VBA] Check if an integer is contained in a range of cells in a worksheet

  1. #1
    Registered User
    Join Date
    03-25-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    3

    Question [VBA] Check if an integer is contained in a range of cells in a worksheet

    Hi,

    I'm sure there is a very simple answer but I've been searching for 25 minutes and I've had no luck.

    In my VBA code, I've got an integer i = 20 (for example).

    In my worksheet, I've got a column of values (e.g. 4, 6, 12, 20, 22, 45)

    I want to write an IF statement to see if i is in that column. If it is, I'll run <something>

    If that fails, I want to check if i is in another column of values (e.g. 2, 3, 23, 46) and if it is, then I'll run <something>

    Otherwise error.

    Do I need a loop for this? Or can I compare the value to a 'range' of cells in a worksheet?

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: [VBA] Check if an integer is contained in a range of cells in a worksheet

    you could use a countif function, something like this


    Please Login or Register  to view this content.
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Valued Forum Contributor
    Join Date
    03-14-2012
    Location
    Arizona USA
    MS-Off Ver
    Excel 2000/2007
    Posts
    408

    Re: [VBA] Check if an integer is contained in a range of cells in a worksheet

    In code, what you are asking for looks like this;

    Please Login or Register  to view this content.

+ 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