+ Reply to Thread
Results 1 to 5 of 5

Formula which checks whether a string is found in a range and checks 2 criteria

  1. #1
    Registered User
    Join Date
    04-29-2012
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    17

    Formula which checks whether a string is found in a range and checks 2 criteria

    Hi,

    I wrote a module which suppose to receive a range ,int and a string as input.

    The module should iterate over the range to find the row in the range that its value = string input.

    When it finds it - it needs to check 2 things:
    1) if inputint >= int in the same row of match string (1 column to the right)
    2) if inputint <= int in the same row of match string (2 column to the right)

    This is the code:

    Please Login or Register  to view this content.

    I'm new to VB so I must be making a basic mistake - the error I get is " Compile Error - Argument not optional "

    I think the error is either in the function signature "str As String" or in the if statment rCell.Value = str, Dunno if its possible to compare a string to rCell.Value?

    Thx in advance!

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Formula which checks whether a string is found in a range and checks 2 criteria

    Maybe thuis

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-29-2012
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula which checks whether a string is found in a range and checks 2 criteria

    Thx Phillips, it partially works, there's a problem tho,

    If CheckIfInRange = true, the loop doesn't end, I need the loop to end when the condition is true,

    Is it possible to change the code line to:

    CheckIfInRange = (CheckIfInRange) OR ( (rCell.Value = str) And (rCell.Offset(0, 1).Value <= i) And (rCell.Offset(0, 2) >= i ) )

    ?
    if it was once set to true, it will stay true till the loop ends, at least theoretically..

    Update: it doesn't work - is it possible to issue break on the loop?

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Formula which checks whether a string is found in a range and checks 2 criteria

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-29-2012
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula which checks whether a string is found in a range and checks 2 criteria

    Thanks Phillps,

    This forum rocks btw!

+ 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