Consulting

Results 1 to 3 of 3

Thread: Lookup Value in Range for an If Statement

  1. #1
    VBAX Regular
    Joined
    Oct 2012
    Posts
    35
    Location

    Lookup Value in Range for an If Statement

    Hello Experts,

    I have a situation where I have Variable X. I want to look to see if that variable is in a Range on another Sheet ("Summary"). I am trying to use it with an If statement. I tried something like this, and it doesn't seem to work. I am sure I am missing something small. I dont need to return the value, just run the IF statement if its found, if not, end if.

    If Sheets("Summary").Columns("B17:B" & Cells(Rows.Count, "C").End(xlUp).Row).Find(What:=X, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)  Then
    Thanks!
    Sean

  2. #2
    VBAX Regular
    Joined
    Oct 2012
    Posts
    35
    Location
    I was able to use the Match function to get it to work, here is the code I used.

    CC = ActiveSheet.Cells(RowCnt, ColCnt - 2).Value
        IsCC = Application.Match(CC, Worksheets("Summary").Range("B16:B" & Cells(Rows.Count, "B").End(xlUp).Row), 0)
        On Error Resume Next
        If IsCC <> 0 Then

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Haven't tried the code but Find is usually preferable in VBA. Were you looking for a date?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •