+ Reply to Thread
Results 1 to 5 of 5

Comparing 2 columns

  1. #1
    Registered User
    Join Date
    07-01-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    6

    Comparing 2 columns

    Hi guys! I have an issue i just cannot figure out. I want to check column A for the number 1 and then when a 1 is found , check the corresponding row in column B and detect if it is a "Y" or an "N". I then want to return a FALSE if there is an "N" in the corresponding row to any occurence of the number 1. If there is no "N" in any corresponding row to any 1's then i want to return a TRUE.

    Is this even possible? Thank you in advance for all your help.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Comparing 2 columns

    I put the result in column C:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Comparing 2 columns

    Maybe this...

    Assuming your data starts on row 2...

    Enter this formula in C2 and copy down as needed:

    =IF(A2=1,IF(B2="N",FALSE,TRUE),"")

    You didn't say what result you want if cells in column A do not =1 so I wrote the formula to return a blank in that case. I'm also assuming that column B will only contain either Y or N, nothing else and no empty cells.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    07-01-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Comparing 2 columns

    Quote Originally Posted by xladept View Post
    I put the result in column C:

    Please Login or Register  to view this content.
    This is working beautifully! thank you!
    I wish to expand on this however and im stumped. I want the macro to check column C and if there is any "FALSE" return "RED" to cell F1.
    I tried the following -
    Sub TF(): Dim A As Range
    For Each A In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    If A = 1 Then
    If UCase(A.Offset(0, 1)) = "N" Then
    A.Offset(0, 2) = "False"
    Else: A.Offset(0, 2) = "True"
    End If: End If: Next: End Sub
    Sub TG(): Dim A As Range
    For Each A In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    If A = 1 Then
    If UCase(A.Offset(0, 2)) = "FALSE" Then
    F1 = "RED"
    Else: F2 = "GREEN"
    End If: End If: Next: End Sub

    For some reason this does not return anything to F1 Any suggestions?

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Comparing 2 columns

    Try:

    Please Login or Register  to view this content.
    But - I don't know why you want that - do you want them in the same row instead??
    Last edited by xladept; 07-02-2013 at 01:43 PM.

+ 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