duplicates across sheets

D

davewars

I'm trying to have the cell text / background colour change when
someone enters a duplicate value, I could use countif function but
need this to work across sheets. Anyone got some VBA to help
 
D

David McRitchie

Hi Dave,
You've not indicated how use of COUNTIF would not work
for you. What do you mean by across sheets. How is that
to be applied. Conditional Formatting only works on one
sheet is that what you are referring to. You will have to
get the information that Conditional Formatting needs on
the same page as it is used.

Chip Pearson has a page (or pages?) on duplicates
http://www.cpearson.com/excel/topic.htm
using COUNTIF

I have a page on Conditional Formatting
http://www.mvps.org/dmcritchie/excel/condfmt.htm

Then again someone has probably asked a similar
question (group:*Excel* is redundant, was used on URL)
this might provide a starting place and add coloring afterwards
http://groups.google.com/advanced_group_search?q=group:*Excel*&num=100
Search for all words: countif multiple sheets duplicate* group:*Excel*

such as the following:
http://google.com/groups?threadm=eSKvdks#BHA.2388@tkmsftngp02
 
F

Frank Kabel

Hi
try the following:
- Create a list with all your worksheets you want to check. e.g. put
them in a range
- Define a name for this range of worksheet names (e.g. call this list
'wslist')
- I assume your input range is on all sheets A1:A100
- now select the input range on one sheet A1:A100 and in the
conditional Format dialog enter the following formula:
=SUMPRODUCT(COUNTIF(INDIRECT("'" & wslist&"'!A1:A100"),A1))>1
- choose a format
 
F

Frank Kabel

Hi David
using a defined name allows also referring to information on other
sheets :)
 
D

davewars

Thanks for these replies, you're right David I meant conditiona
formatting. the full problem is that new sheets will be added ever
week so (i don't think??) a defined name would work unless this wa
dynamically updated. the link i added to my post was ideal except
need it modified to highlight the cells that are duplicated in som
way.
Thanks
David
 
F

Frank Kabel

Hi
see my post. For a dynamic name definition try something like the
following:
- enter your worksheet names on a separate sheet in the cell A1:Ax
- define a name with the following formula
=OFFSET('name_sheet'!$A$1,0,0,COUNTA('name_sheet'!$A:$A))

Now the only thing you have to do is manually adding the new sheet
names. The name will change automatically
 
D

davewars

Thanks Ken, but the prob is that this will be updated by someone with n
/ v.little experience in Excel and I have the distinct feeling that th
name would not be updated hence the need for a macro or automatic a
least solution involving no useer input. Not sure but wouldn't formul
only return one sheet name also? so that it update but only search th
new sheet for duplicates?
Thanks for the hel
 
D

David McRitchie

Hi Frank,
The problem was they have to manually update the list.
That's why I didn't mention named list, because I thought
it would be too messy but since you've got it mostly worked
out -- all that's really needed is an Event macro to keep
the list of worksheetnames up-to-date.

Hi DaveWar,
The downside of making things easy for the user, is making
it more difficult to maintain. So would suggest putting
some comments on the "ListOfSheets" worksheet.

Place the following event macro
into "ThisWorkbook" at the end of "Microsoft
Excel Objects" (before the list of sheetname)
in the Visual Basic Editor (F11, Ctrl+R)
will update the ranges and create the wsList
defined name. You must have a worksheet
named "ListOfSheets".

The list will be updated everytime the user selects
(activates) a worksheet. It will not include a
worksheet named "Master" nor one named
"ListOfSheets".

Option Explicit

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim i As Long
Dim wkSheet As Worksheet
With Sheets("ListOfSheets")
.Range("A:A").Clear
i = 0
For Each wkSheet In Application.Worksheets
If LCase(wkSheet.Name) <> "master" _
And wkSheet.Name <> .Name Then
i = i + 1
.Cells(i, 1) = wkSheet.Name
End If
Next wkSheet
ActiveWorkbook.Names.Add _
Name:="wslist", RefersTo:=.Range("A1:A" & i)
End With
End Sub

More information on Event macros on my page
http://www.mvps.org/dmcritchie/excel/event.htm
 
D

David McRitchie

Hi Frank,
Thanks, but I must have put your array formula in the
wrong spot or something, I think that it should not
react to any changes on the master worksheet,
but if I make changes to A1 on the master worksheet
I get the formula value changing. From True to False

B1: =SUMPRODUCT(COUNTIF(INDIRECT("'" & wslist&"'!A1:A100"),A1))>1
entered as an array formula: Ctrl+Shift+Enter
 
F

Frank Kabel

Hi David
- no need for array entering this formula. Works fine
entered normally :)
- The reaction to the master sheet depends on wslist. I've
tried both. Without including the master sheet in this
list the formula should only react on changes on the other
sheets. If you include the master sheet in this list the
formula will also find duplicated in the master sheet

Note: One drawback of this approach: This formula used in
conditional format will highlight not only the second
entry (the duplicate) but all values that are duplicates
(a little bit different than the normal COUNTIF approach
which will highlight startring at the second occurence of
any value)
 
Top