Results 1 to 10 of 12

Thread: VBA Program to Compare 4 Columns in Excel (Required)

Threaded View

vijaysram VBA Program to Compare 4... 06-19-2013, 11:21 PM
Excel Fox Hi vijaysram, welcome to... 06-20-2013, 12:16 AM
vijaysram Hi Exelfox, Thanks for your... 06-20-2013, 08:04 AM
Excel Fox Try this Private Sub... 06-20-2013, 11:12 AM
vijaysram I tried the above VBA code... 06-20-2013, 11:08 PM
Excel Fox So if a value is found on all... 06-20-2013, 11:49 PM
vijaysram Hi The Macro should ask us... 06-21-2013, 07:32 AM
Excel Fox Here's a revised one ... 06-21-2013, 05:17 PM
Excel Fox Try this Private Sub... 06-21-2013, 01:24 PM
vijaysram Hi Something problem with... 06-21-2013, 11:25 PM
Admin Hi Vijay, Please do not... 06-22-2013, 01:43 PM
vijaysram Thank you so much for your... 06-26-2013, 10:53 AM
Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0

    VBA Program to Compare 4 Columns in Excel (Required)

    Hi all

    I am New to VBA programming in Excel. Can someone please help me how to create a VBA Program to Compare 4 Columns in Excel and store the values in another column. I have searched it in multiple websites but i couldn't find it. I have got a VBA to compare 2 columns , please let me know how to create it for 4 columns
    Code:
    Private Sub CommandButton1_Click()
    Dim CompareRange As Variant, To_Be_Compared As Variant, x As Variant, y As Variant
    str1 = InputBox("Enter Column Name to be Compared")
    str2 = InputBox("Enter Column Name to Compare")
    str3 = InputBox("Enter Column Name to put the Result")
    Range(str1 & "1").Select
    Selection.End(xlDown).Select
    Set To_Be_Compared = Range(str1 & "1:" & Selection.Address)
    Range(str2 & "1").Select
    Selection.End(xlDown).Select
    Set CompareRange = Range(str2 & "1:" & Selection.Address)
    i = 1
    To_Be_Compared.Select
    For Each x In Selection
    For Each y In CompareRange
    If x = y Then
    Range(str3 & i).Value = x
    i = i + 1
    End If
    Next y
    Next x
    End Sub
    Last edited by Excel Fox; 06-20-2013 at 12:14 AM. Reason: Code Tags

Similar Threads

  1. Absolute Calender Program!
    By Preeti Verma in forum Excel Help
    Replies: 1
    Last Post: 11-06-2012, 01:19 PM
  2. Validating 2 Columns using excel VBA
    By freakszzy in forum Excel Help
    Replies: 2
    Last Post: 07-26-2012, 12:46 PM
  3. compare column a to b and b to a
    By ayazgreat in forum Excel Help
    Replies: 18
    Last Post: 05-07-2012, 04:46 PM
  4. Replies: 1
    Last Post: 11-11-2011, 02:06 PM
  5. Compare two worksheets and List Differences
    By excel_learner in forum Excel Help
    Replies: 1
    Last Post: 11-02-2011, 10:03 PM

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
  •