+ Reply to Thread
Results 1 to 4 of 4

Help comparing values in two columns and displaying the value in another column

Hybrid View

  1. #1
    Registered User
    Join Date
    08-13-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2016,2016,365
    Posts
    92

    Help comparing values in two columns and displaying the value in another column

    Hello

    I am trying to compare values in two columns and return the value in another. What I have so far works however, in column O there is already the value "Trainee" which means its returning the value "Trainee Manual" even when it does not match Babcock - Weekly. Sure I need an Or in there but not very good at them.

    Sub Test()
        Dim LastRow As Long
        Dim i As Long
        LastRow = Range("P" & Rows.Count).End(xlUp).Row
        For i = 2 To LastRow
            'If i = 615 Then
             'MsgBox ("Here")
            'End If
            If Range("P" & i).Value = "Babcock - Weekly" Then
                If Range("O" & i).Value = "Apprentice"  Then
                   Range("N" & i).Value = "Trainee - Manual"
                
    			
              End if
    		  End If
                    If Range("O" & i).Value = "Trainee" Then
                        Range("N" & i).Value = "Trainee - Manual"
            
                
           
                   
                
            End If
        Next i
    End Sub
    Thanks

    Ross

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,656

    Re: Help comparing values in two columns and displaying the value in another column

    Check if that works as desired:
        For i = 2 To LastRow
            'If i = 615 Then
             'MsgBox ("Here")
            'End If
    
            If Range("P" & i).Value = "Babcock - Weekly" Then
                If Range("O" & i).Value = "Apprentice"  or Range("O" & i).Value = "Trainee" Then
                   Range("N" & i).Value = "Trainee - Manual"
                End if
            End If
    next i
    Best Regards,

    Kaper

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Help comparing values in two columns and displaying the value in another column

    Hi rosscortb,

    Does this do what you expect?

    Sub Test()
    
    Dim LastRow As Long
    Dim i As Long
    
    LastRow = Range("P" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
        'If i = 615 Then
        'MsgBox ("Here")
        'End If
        If Range("P" & i).Value = "Babcock - Weekly" And (Range("O" & i).Value = "Apprentice" Or Range("O" & i).Value = "Trainee") Then
            Range("N" & i).Value = "Trainee - Manual"
        End If
    Next i
    
    End Sub
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Registered User
    Join Date
    08-13-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2016,2016,365
    Posts
    92

    Re: Help comparing values in two columns and displaying the value in another column

    Thanks Arkadi, your one worked perfectly, thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 01-07-2016, 12:03 PM
  2. Replies: 3
    Last Post: 08-25-2015, 02:03 PM
  3. [SOLVED] Comparing Values in Two Columns and Returning Value from another Column
    By GOPALAKRISHNANGK in forum Excel General
    Replies: 4
    Last Post: 11-12-2014, 01:46 AM
  4. Replies: 10
    Last Post: 10-09-2014, 09:20 AM
  5. Replies: 19
    Last Post: 03-15-2014, 04:50 PM
  6. [SOLVED] Comparing 2 columns and Displaying the associated row in another column
    By William123 in forum Excel General
    Replies: 25
    Last Post: 04-12-2012, 08:18 AM
  7. Comparing values in two columns and displaying missing values in n
    By cpetta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2005, 11:29 PM

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