ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   comparsions of columns and deletion (https://www.excelbanter.com/excel-programming/342912-comparsions-columns-deletion.html)

sreedhar[_13_]

comparsions of columns and deletion
 

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
11,00,10,10
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


Tom Ogilvy

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" wrote in
message ...

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
11,00,10,10
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




sreedhar[_14_]

comparsions of columns and deletion
 

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


Tom Ogilvy

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" wrote in
message ...

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




sreedhar[_16_]

comparsions of columns and deletion
 

hi tom

thanks a lot for u'r help


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



All times are GMT +1. The time now is 06:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com