Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Member
 
Posts: 89
Post Finding Duplicate Rows & Highlighting them

I have data in a worksheet that contains both numbers & text.

I want to find a formula or Macro that can search the entire sheet and ONLY highlight the rows that are duplicated. Not just the first cell, the whole row.

The data goes from Column A to Column M.

I don't want them deleted or moved - only highlighted.

Any/all assistance would be greatly appreciated.

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 538
Default Finding Duplicate Rows & Highlighting them

frankjh19701 wrote:

I have data in a worksheet that contains both numbers & text.

I want to find a formula or Macro that can search the entire sheet and
ONLY highlight the rows that are duplicated. Not just the first cell,
the whole row.

The data goes from Column A to Column M.

I don't want them deleted or moved - only highlighted.


This will bold the duplicated rows. Other methods of "highlighting" are
possible, just depends on what you want.

Sub findDupsAndBold()
For L0 = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row - 1
For L1 = L0 + 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
theSame = True
For L2 = 1 To Cells.SpecialCells(xlCellTypeLastCell).Column
If Cells(L0, L2).Value < Cells(L1, L2).Value Then
theSame = False
Exit For
End If
Next
If theSame Then
Rows(L0).Font.Bold = True
Rows(L1).Font.Bold = True
End If
Next
Next
End Sub

(There are probably better ways to do this, but I already had a similar thing
written.)

--
- I'm not the type to be led around by woman.
- Then lead her around.
- I'm even less the type to do that.
  #3   Report Post  
Member
 
Posts: 89
Post

I just tried it and it worked great!

How would I highlight the rows?

Quote:
Originally Posted by Auric__ View Post
frankjh19701 wrote:

I have data in a worksheet that contains both numbers & text.

I want to find a formula or Macro that can search the entire sheet and
ONLY highlight the rows that are duplicated. Not just the first cell,
the whole row.

The data goes from Column A to Column M.

I don't want them deleted or moved - only highlighted.


This will bold the duplicated rows. Other methods of "highlighting" are
possible, just depends on what you want.

Sub findDupsAndBold()
For L0 = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row - 1
For L1 = L0 + 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
theSame = True
For L2 = 1 To Cells.SpecialCells(xlCellTypeLastCell).Column
If Cells(L0, L2).Value < Cells(L1, L2).Value Then
theSame = False
Exit For
End If
Next
If theSame Then
Rows(L0).Font.Bold = True
Rows(L1).Font.Bold = True
End If
Next
Next
End Sub

(There are probably better ways to do this, but I already had a similar thing
written.)

--
- I'm not the type to be led around by woman.
- Then lead her around.
- I'm even less the type to do that.
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 538
Default Finding Duplicate Rows & Highlighting them

frankjh19701 wrote:

Auric__ Wrote:
frankjh19701 wrote:
-
I have data in a worksheet that contains both numbers & text.

I want to find a formula or Macro that can search the entire sheet and
ONLY highlight the rows that are duplicated. Not just the first cell,
the whole row.

The data goes from Column A to Column M.

I don't want them deleted or moved - only highlighted.-


This will bold the duplicated rows. Other methods of "highlighting" are
possible, just depends on what you want.

[snip code]
(There are probably better ways to do this, but I already had a similar
thing written.)


I just tried it and it worked great!

How would I highlight the rows?


(Please don't top post.)

It depends on what you mean by "highlight". If you want it painted yellow,
as if using a highlighter pen, change this:

Rows(L0).Font.Bold = True
Rows(L1).Font.Bold = True

to this:

Rows(L0).Interior.Color = vbYellow
Rows(L1).Interior.Color = vbYellow

I use bold for my own stuff, but as I said, there are ways and ways.

--
You looking at my hog? Don't look at my hog... or my motorcycle.
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,514
Default Finding Duplicate Rows & Highlighting them

A couple of ways...

Option Explicit

Const lColorNdx = 36 '//light yellow

Sub HighlightDupeRows()
Dim lRows&, lCols&, n&, k&, r, r1, r2
With ActiveSheet.UsedRange
lRows = .Rows.Count: lCols = .Columns.Count
End With
For Each r In ActiveSheet.UsedRange.Rows
For n = 1 To lRows - 1
For k = 1 To lCols
r1 = r1 & Cells(r.Row, k).Value
r2 = r2 & Cells(n + 1, k).Value
Next 'k
If r1 = r2 And r.Row < (n + 1) Then
Rows(r.Row).Interior.ColorIndex = lColorNdx
Rows(n + 1).Interior.ColorIndex = lColorNdx
End If
r1 = "": r2 = ""
Next 'n
Next 'r
End Sub

Sub HighlightDupeRows2()
Dim v1, v2, n&, k&, r&, r1, r2
v1 = ActiveSheet.UsedRange
For r = 1 To UBound(v1) - 1
For n = 2 To UBound(v1)
r1 = "": r2 = ""
For k = 1 To UBound(v1, 2)
r1 = r1 & v1(r, k): r2 = r2 & v1(n, k)
Next 'k
If r1 = r2 And n < r Then
Rows(n).Interior.ColorIndex = lColorNdx
Rows(r).Interior.ColorIndex = lColorNdx
End If 'r1=r2
Next 'n
Next 'r
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #6   Report Post  
Member
 
Posts: 89
Default

Quote:
Originally Posted by GS[_2_] View Post
A couple of ways...

Option Explicit

Const lColorNdx = 36 '//light yellow

Sub HighlightDupeRows()
Dim lRows&, lCols&, n&, k&, r, r1, r2
With ActiveSheet.UsedRange
lRows = .Rows.Count: lCols = .Columns.Count
End With
For Each r In ActiveSheet.UsedRange.Rows
For n = 1 To lRows - 1
For k = 1 To lCols
r1 = r1 & Cells(r.Row, k).Value
r2 = r2 & Cells(n + 1, k).Value
Next 'k
If r1 = r2 And r.Row < (n + 1) Then
Rows(r.Row).Interior.ColorIndex = lColorNdx
Rows(n + 1).Interior.ColorIndex = lColorNdx
End If
r1 = "": r2 = ""
Next 'n
Next 'r
End Sub

Sub HighlightDupeRows2()
Dim v1, v2, n&, k&, r&, r1, r2
v1 = ActiveSheet.UsedRange
For r = 1 To UBound(v1) - 1
For n = 2 To UBound(v1)
r1 = "": r2 = ""
For k = 1 To UBound(v1, 2)
r1 = r1 & v1(r, k): r2 = r2 & v1(n, k)
Next 'k
If r1 = r2 And n < r Then
Rows(n).Interior.ColorIndex = lColorNdx
Rows(r).Interior.ColorIndex = lColorNdx
End If 'r1=r2
Next 'n
Next 'r
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
This worked out great! Thank you!
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,514
Default Finding Duplicate Rows & Highlighting them

This worked out great! Thank you!

You are welcome. I appreciate the feedback!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Duplicate Rows (Macro) Edwin Excel Discussion (Misc queries) 2 July 2nd 09 09:02 PM
Finding duplicate values and deleting both rows [email protected] Excel Programming 3 May 16th 07 10:28 AM
Finding Duplicate Rows Secret Squirrel Excel Discussion (Misc queries) 1 April 8th 07 05:49 AM
finding duplicate rows [email protected] Excel Worksheet Functions 1 June 16th 06 01:31 PM
Deleting/highlighting duplicate rows Sharon Excel Programming 4 November 13th 04 08:12 PM


All times are GMT +1. The time now is 11:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"