Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Search for duplicates in a column

Hi,

I am trying to figure out how to search through column B of Sheet1. If
there are duplicates, display a message stating such, with the duplicate
value contained in the msgbox.

ideas?
--
Carlee
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Search for duplicates in a column

On Apr 26, 9:38 pm, Carlee wrote:
Hi,

I am trying to figure out how to search through column B of Sheet1. If
there are duplicates, display a message stating such, with the duplicate
value contained in the msgbox.

ideas?
--
Carlee


Why not sort the data, and then compare one cell with the next?

For example

Dim currCell
Dim nextCell
Dim counter
Dim a

counter = activesheet.range("b2").currentregion.rows.count 'or use
usedrange...

for a = 1 to counter
currCell = range("b" & a).value
nextCell = range("b" & a).offset(1,0).value
if currCell = nextCell then
msgbox prompt:="You have a duplicate." & vbcr _
& "The value is " & currCell & vbcr _
& "The location is " a & " & " & a + 1, buttons:=vbOkOnly
end if
next

Matt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Search for duplicates in a column

On Apr 26, 9:38 pm, Carlee wrote:
Hi,

I am trying to figure out how to search through column B of Sheet1. If
there are duplicates, display a message stating such, with the duplicate
value contained in the msgbox.

ideas?
--
Carlee


Why not sort the data and then compare one cell with the other?

for example (not tested)

dim currCell
dim nextCell
dim counter
dim a

counter = activesheet.range("b1").currentregion.rows.count 'or use
usedrange...

for a = 1 to counter
currCell = range("b" & a).value
nextCell = range("b" & a).offset(1,0).value

if currCell = nextCell then
msgbox prompt:="You have a duplicate." & vbcr _
& "The value is " & currCell & vbcr _
& "The location is " & a & " & " a + 1,
buttons:=vbokonly
end if
next

matt

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
Search for duplicates across three worksheets Sarah_Lund Excel Worksheet Functions 1 May 20th 08 12:29 AM
search for duplicates enyaw Excel Programming 5 August 22nd 06 03:32 PM
how do I search a colum for duplicates automatically Andrew Excel Discussion (Misc queries) 2 February 8th 06 02:45 PM
search range for duplicates Doug Loewen[_2_] Excel Programming 3 April 16th 04 04:18 PM
Word Search from Excel results in Duplicates Sarvesh Excel Programming 2 December 23rd 03 05:23 PM


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

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

About Us

"It's about Microsoft Excel"