+ Reply to Thread
Results 1 to 3 of 3

Facing problem in a Macro which compares 2 columns having comma separated / single values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-12-2013
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    147

    Facing problem in a Macro which compares 2 columns having comma separated / single values

    Hello Guys,

    I am facing an error in a Macro and need your help in resolving the same.

    I am using a Macro in attached file for comparing the delimited separated values between 2 columns.

    In attached file I am comparing the values present in Column C and D with Column A. If Column C is containing a unique value (the value of Column A is different) then Column E will mark as 1 else 0. Same thing we do with Column D and if there is unique value then Column F will mark as 1 else 0.

    Issue – The problem I am facing in a Macro is if Column C or D is not having any entry then the Macro will generate 1 in first cell of Column E or F (for example please check cell marked as yellow in attached file).

    I want if there is no value in Column C or D then Macro should not generate any value in Column E or F.

    Please refer the attached “Sample” Macro file.

    Thanks,
    MG
    Attached Files Attached Files
    Last edited by Manish_Gupta; 03-18-2014 at 11:19 PM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Facing problem in a Macro which compares 2 columns having comma separated / single val

    Try,

    Option Explicit
    Sub ertert_Updated()
    Dim s$, sp, x, i&, j&, k&, y, LR&
    s = Join(Application.Transpose(Range("A2", Cells(Rows.Count, 1).End(xlUp))), ",")
    x = Range("C2", Cells(Rows.Count, 3).End(xlUp)).Value
    For i = 1 To UBound(x)
        If Len(x(i, 1)) Then
            sp = Split(x(i, 1), ",")
            k = 0
            For j = 0 To UBound(sp)
                If InStr(s, Trim(sp(j))) = 0 Then k = k + 1
            Next j
        If k > 1 Then
            x(i, 1) = 1
        Else
        x(i, 1) = k
        End If
        
        End If
    Next i
    Range("E2").Resize(i - 1).Value = x
    
      LR = Range("D" & Rows.Count).End(xlUp).Row
       If LR <= 1 Then Exit Sub
      y = Range("D1:D" & LR)
    For i = 2 To UBound(y)
        If Len(y(i, 1)) Then
            sp = Split(y(i, 1), ",")
            k = 0
            For j = 0 To UBound(sp)
                If InStr(s, Trim(sp(j))) = 0 Then k = k + 1
            Next j
        If k > 1 Then
            y(i, 1) = 1
        Else
        y(i, 1) = k
        End If
        
        End If
    Next i
    Range("F2").Resize(i - 1).Value = y
    
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-12-2013
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    147

    Re: Facing problem in a Macro which compares 2 columns having comma separated / single val

    Hello AB33,

    Thanks for the wonderful solution.

+ 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] Macro to give the count of unique values after comparing the comma separated values
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2014, 12:41 AM
  2. Replies: 3
    Last Post: 12-23-2013, 12:32 PM
  3. Comma Separated values in Rows and columns
    By abhijeet_gole in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2013, 12:45 AM
  4. [SOLVED] Single cell Comma Separated Values to validation list [DIFFICULT QUESTION]
    By jgema in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-31-2013, 08:48 PM
  5. [SOLVED] Macro to match values in cells separated by semicolon and comma
    By Ale84 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2013, 11:00 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