Consulting

Results 1 to 5 of 5

Thread: Basic question on cell comparison

  1. #1
    VBAX Newbie
    Joined
    Mar 2011
    Posts
    2
    Location

    Basic question on cell comparison

    I am new to VBA, so this is probably a very dum question. I am trying to compare cells in one column to those in another. I.e. I choose a cell in one column, and I want to check if its content exists in the second column. Cells contain strings. I am writing:
    For i = 0 To composerCount
    If Cells(r, 9).Value = Cells(i, 20).Value Then
    isNew = False
    End If
    I have also tried without the .Value, but neither work. What is the correct syntax?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is how it is done, so what is the problem?

    Maybe you just want t check if it exists in any row?

    [vba]

    For i = 0 To composerCount

    isNew = IsError(Application.Match(Cells(r, 9).Value, Columns(20),0))
    Next i
    [/vba]
    ____________________________________________
    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

  3. #3
    VBAX Newbie
    Joined
    Mar 2011
    Posts
    2
    Location
    Quote Originally Posted by xld
    That is how it is done, so what is the problem?

    Maybe you just want t check if it exists in any row?

    [vba]

    For i = 0 To composerCount

    isNew = IsError(Application.Match(Cells(r, 9).Value, Columns(20),0))
    Next i
    [/vba]
    Thanks for the reply. When I use the code I wrote, I get:
    I get Run-time Error '1004': Application-defined or object-defined error.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post the whole of your code so we can see how IsNew is implemented.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by yoelgr
    Thanks for the reply. When I use the code I wrote, I get:
    I get Run-time Error '1004': Application-defined or object-defined error.
    I doubt that error is in that code.

    As MD suggested, post the workbook or all the code for us to see.
    ____________________________________________
    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

Posting Permissions

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