+ Reply to Thread
Results 1 to 6 of 6

Need to Compare Values in Multiple Columns

  1. #1
    Registered User
    Join Date
    08-27-2013
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    10

    Need to Compare Values in Multiple Columns

    I need to compare values in Column B to values in Column P to see if they are the same (note, these are two different sets of data so, the identical values we are searching for might be in B12 and P55. If we find the same value in B and P then we need to compare the value contained on the same row to B, the value for C and then on the same row as P, the value for Q. If C and Q DO NOT MATCH, in column R I would like to put the words, "Wrong Amt."

    Thanks in advance.

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Need to Compare Values in Multiple Columns

    Try this code to see if this works as per your requirement.
    Please Login or Register  to view this content.
    See the attached sheet.
    Attached Files Attached Files
    Last edited by sktneer; 05-12-2014 at 02:29 PM.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need to Compare Values in Multiple Columns

    sktneer,

    I have a very similar situation and used your code to much success.

    I have a follow-up question: How would I go about getting this code to generate a report of variances on the next sheet of the workbook? This report should include the values from columns B, C, P and Q.

    Also, I made a few minor changes to your code:

    Sub comparevalues()
    Columns("R:S").Delete
    Dim rng, rng1, cell As Range
    Dim lr As Long
    Dim n As Integer
    lr = Cells(Rows.Count, 2).End(xlUp).Row
    Set rng = Range("B2:B" & lr)
    Set rng1 = Range("P2:P" & lr)
    Application.ScreenUpdating = False
    For Each cell In rng
    On Error Resume Next
    n = WorksheetFunction.Match(cell, rng1, 0)
    If Err = 0 Then
    If cell.Offset(0, 1) <> Cells(n + 1, "Q") Then
    Cells(n + 1, "R") = "Wrong Amount"
    Cells(n + 1, "S") = cell.Offset(0, 1)
    End If
    End If
    Err = 0
    Next cell
    Columns("R:S").AutoFit
    Application.ScreenUpdating = True
    End Sub

    Thanks,

    jphart99

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Need to Compare Values in Multiple Columns

    Find the attached sheet to see if this works as per your requirement. The columns of interest will be copied to Sheet2.
    Attached Files Attached Files
    Last edited by sktneer; 05-13-2014 at 12:19 PM.

  5. #5
    Registered User
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need to Compare Values in Multiple Columns

    Sktneer,

    Thanks very much for your help! This has worked very well!

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Need to Compare Values in Multiple Columns

    You're welcome.
    If that takes care of your question, please mark your thread as solved by selecting Thread Tools (just above your first post) --> Mark thread as solved.
    Moreover you may also click on * (star) to Add Reputation to those who have put their time and efforts to help you in this forum. This is another way to say thanks to them.

+ 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. [SOLVED] Need to compare multiple values including TIME between, and compare rate
    By fourmurphys in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-21-2014, 04:37 PM
  2. Replies: 5
    Last Post: 10-26-2013, 01:03 PM
  3. Replies: 0
    Last Post: 10-07-2013, 10:24 AM
  4. compare values multiple columns
    By allaud in forum Excel General
    Replies: 5
    Last Post: 07-12-2011, 09:16 AM
  5. Compare Values in Multiple Columns and return a result
    By edbhome in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-18-2009, 09:37 AM

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