+ Reply to Thread
Results 1 to 5 of 5

comparsions of columns and deletion

Hybrid View

  1. #1
    Tom Ogilvy
    Guest

    Re: comparsions of columns and deletion

    Sub ABC()
    Dim lastrow As Long, i As Long
    Dim bGreater As Boolean
    Dim j As Long
    lastrow = Cells(Rows.Count, 1).End(xlUp).Row
    i = 1
    Do While Cells(1, i + 1) <> ""
    bGreater = True
    For j = 1 To lastrow
    If Cells(j, i) < Cells(j, i + 1) Then
    bGreater = False
    Exit For
    End If
    Next
    If bGreater Then
    Columns(i).EntireColumn.Delete
    Else
    i = i + 1
    End If
    Loop
    End Sub

    --
    Regards,
    Tom Ogilvy

    "sreedhar" <sreedhar.1wy8ab_1129388704.5241@excelforum-nospam.com> wrote in
    message news:sreedhar.1wy8ab_1129388704.5241@excelforum-nospam.com...
    >
    > hi,
    >
    > i want a macro for comparing columns.
    >
    >
    > for ex
    >
    > A B C
    > 1 1 1 .........
    > 0 0 0 .........
    > 1 0 0 .........
    > 1 0 1 .........
    > .......
    > .........
    > .......
    >
    >
    > if A compared with B
    > 1>1,0>0,1>0,1>0
    > so A is greater than B so column A should be deleted
    >
    > like wise we have to compare each and every cell in the column
    > and compare all columns up to end of excel sheet
    >
    > So,plz can any one help me regarding this
    >
    > thanks
    > sree
    >
    >
    > --
    > sreedhar
    > ------------------------------------------------------------------------
    > sreedhar's Profile:

    http://www.excelforum.com/member.php...o&userid=27582
    > View this thread: http://www.excelforum.com/showthread...hreadid=476492
    >




  2. #2
    Registered User
    Join Date
    09-27-2005
    Posts
    16
    hi tom

    u'r marco is comparing columns like this way

    A compared B
    B compared C
    C compared D
    D compared E and so on

    but what i need is :

    A should compare with B , if B is greater than A then B should be deleted ,
    and then A should compare with C if C is deleted
    then should compare D and So on .
    or
    if A is greater than B, than A should be deleted,and next
    B should compare with C and So on.

    So,plz help me regrading this

    thanks
    sree

  3. #3
    Tom Ogilvy
    Guest

    Re: comparsions of columns and deletion

    Sub ABC()
    Dim lastrow As Long, i As Long
    Dim bGreater As Boolean
    Dim j As Long, k As Long
    Dim lastcol As Long
    lastcol = Cells(1, 256).End(xlToLeft).Column
    lastrow = Cells(Rows.Count, 1).End(xlUp).Row
    i = 1
    Do While Cells(1, i + 1) <> ""
    For k = i + 1 To lastcol
    bGreater = True
    For j = 1 To lastrow
    If Cells(j, i) < Cells(j, k) Then
    bGreater = False
    Exit For
    End If
    Next j
    If bGreater Then Exit For
    Next k
    If bGreater Then
    Columns(i).EntireColumn.Delete
    Else
    i = i + 1
    lastcol = Cells(1, 256).End(xlToLeft).Column
    End If
    Loop
    End Sub

    --
    Regards,
    Tom Ogilvy


    "sreedhar" <sreedhar.1wzrub_1129460712.799@excelforum-nospam.com> wrote in
    message news:sreedhar.1wzrub_1129460712.799@excelforum-nospam.com...
    >
    > hi tom
    >
    > u'r marco is comparing columns like this way
    >
    > A compared B
    > B compared C
    > C compared D
    > D compared E and so on
    >
    > but what i need is :
    >
    > A should compare with B , if B is greater than A then B should be
    > deleted ,
    > and then A should compare with C if C is deleted
    > then should compare D and So on .
    > or
    > if A is greater than B, than A should be deleted,and next
    > B should compare with C and So on.
    >
    > So,plz help me regrading this
    >
    > thanks
    > sree
    >
    >
    > --
    > sreedhar
    > ------------------------------------------------------------------------
    > sreedhar's Profile:

    http://www.excelforum.com/member.php...o&userid=27582
    > View this thread: http://www.excelforum.com/showthread...hreadid=476492
    >




  4. #4
    Registered User
    Join Date
    09-27-2005
    Posts
    16
    hi tom

    thanks a lot for u'r help


    thanks
    sree

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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