+ Reply to Thread
Results 1 to 3 of 3

Removing duplicate columns

  1. #1
    Registered User
    Join Date
    10-02-2013
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    5

    Removing duplicate columns

    Hi all,

    After searching the forums I couldnt find a simple way to remove duplicates columns.
    Preferrably I would like to avoid transposing my data, Is there any other way?

    Regards,

  2. #2
    Registered User
    Join Date
    10-02-2013
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Removing duplicate columns

    found this on the internet!



    Sub DeleteDuplicateColumns()
    Dim rngData As Range
    Dim arr1, arr2
    Dim i As Integer, j As Integer, n As Integer

    On Error Resume Next
    Set rngData = ActiveSheet.UsedRange
    If rngData Is Nothing Then Exit Sub

    n = rngData.Columns.Count

    For i = n To 2 Step -1
    For j = i - 1 To 1 Step -1
    If WorksheetFunction.CountA(rngData.Columns(i)) <> 0 And _
    WorksheetFunction.CountA(rngData.Columns(j)) <> 0 Then
    arr1 = rngData.Columns(i)
    arr2 = rngData.Columns(j)
    If AreEqualArr(arr1, arr2) Then
    With rngData.Columns(j)
    'mark column to be deleted
    .Copy
    If MsgBox("Delete marked column?", vbYesNo) _
    = vbYes Then
    rngData.Columns(j).Delete
    Else
    'remove mark
    Application.CutCopyMode = False
    End If
    End With
    End If
    End If
    Next j
    Next i

    End Sub
    Function AreEqualArr(arr1, arr2) As Boolean
    Dim i As Long, n As Long
    AreEqualArr = False
    For n = LBound(arr1) To UBound(arr1)
    If arr1(n, 1) <> arr2(n, 1) Then
    Exit Function
    End If
    Next n
    AreEqualArr = True
    End Function

  3. #3
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Removing duplicate columns

    you might also try
    Please Login or Register  to view this content.

+ 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. Removing duplicate in from two columns not in order.
    By bisalk in forum Excel General
    Replies: 5
    Last Post: 10-02-2013, 03:24 AM
  2. Removing Duplicate Rows based on 2 columns
    By metalpoker in forum Excel Programming / VBA / Macros
    Replies: 37
    Last Post: 10-14-2011, 05:28 AM
  3. Removing Duplicate Values - 2 Columns
    By hpaum99 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-27-2010, 12:00 PM
  4. Replies: 1
    Last Post: 04-01-2005, 07:06 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