Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2007, 10:51 AM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XL2003 Sample Macro for Duplicates

 I have used in the past a simple Macro, that a colleague sent me, to enable me to find duplicate items across spreadsheets in Excel 2000. It's subject was "XL200:Sample Macro to Find Duplicate Entries in a Column"
I assumed this would work in Excel 2003 but it does not.

Does anybody else have this problem? or perhaps even a solution?




 
Old May 10th, 2007, 04:00 PM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Without seeing the macro code it would be difficult to determine what the problem is. Is there a specific error you are getting or is it just not working? Does the code highlight or somehow mark duplicates, move them to a different sheet/book, or delete them? Is the duplicated value a single column or the entire row?

I did reply and give a simple sample for determining duplicates requiring a sheet to be sorted but if this goes across spreadsheets and can have duplicates appearing randomly throughout you'd have to set up an array for storing unique values to test against. It may still help give you some ideas, so take a look:
http://p2p.wrox.com/topic.asp?TOPIC_ID=59953

Hope this helps. If what is needed is more involved or dynamic then the specifics need to be clearly outlined/specified.

 
Old May 11th, 2007, 03:07 AM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your feedback Allenm. I'm a real beginner when it comes to this, which basically amounts to this being my first time playing with Macros and VBA. I have copied and pasted the original program lines below. I hope this makes clear what I was looking to do?!
I really appreciate your help on this.



Sub FindDups ()
   '
   ' NOTE: You must select the first cell in the column and
   ' make sure that the column is sorted before running this macro
   '
   ScreenUpdating = False
   FirstItem = ActiveCell.Value
   SecondItem = ActiveCell.Offset(1, 0).Value
   Offsetcount = 1
   Do While ActiveCell <> ""
      If FirstItem = SecondItem Then
        ActiveCell.Offset(Offsetcount,0).Interior.Color = RGB(255,0,0)
        Offsetcount = Offsetcount + 1
        SecondItem = ActiveCell.Offset(Offsetcount, 0).Value
      Else
        ActiveCell.Offset(Offsetcount, 0).Select
        FirstItem = ActiveCell.Value
        SecondItem = ActiveCell.Offset(1,0).Value
        Offsetcount = 1
      End If
   Loop
   ScreenUpdating = True
End Sub


 
Old May 11th, 2007, 08:49 AM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hmmm... I checked this out and it works fine in my copy of Excel 2003 (SP2). I assume that this macro was stored in your personal macro workbook and should be usable across workbooks.

There is one of two things wrong. The easiest first would be to check macro security levels. Try setting the level to medium:
(1) Click Tools > Macro > Security
(2) Make sure Medium is dotted.
(3) Click OK

If this doesn't fix it, then it could be that Personal.xls isn't loading at startup, is missing or is corrupted.

Try finding the personal.xls file. If it's there you could try stopping at step 4 below and checking to see if macros are working again before proceeding.

If you think that personal.xls may be damaged or not working properly then you may have to rename it prior to walking through below steps.

The steps below in their entirety walks through recreating the macro:
(1) Click Tools > Macro > Record Macros
(2) Fill in desired macro name, shortcut key and description. Be sure to select Personal Macro Workbook to Store Macro In.
(3) Click OK.
(4) Immediately click stop button to exit recording of macro.
(5) Click Tools > Macro > Visual Basic Editor
(6) Expand VBAProject (PERSONAL.XLS) if it isn't already.
(7) Expand Modules folder under that.
(8) Check the existing modules by double clicking them and perusing them in the code window.
(9) Find the macro you created, it should only have comments similar to this:
'
' FindDuplicates Macro
' Find duplicates
'
' Keyboard Shortcut: Ctrl+Shift+D
'
(10) Copy the actual code of your macro into the sub right before the End Sub line.
(11) If you find the code already in another sub routine in the personal macro book, it may have been that during install/upgrade of 2003 it lost track of the personal.xls and was no longer set up to auto load it. Delete any duplicate subroutines.
(12) SAVE WORK.

The macro should now be working.

Hope this solves your problem.


 
Old May 11th, 2007, 09:02 AM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are a Legend!!
Thank you very much indeed.
My security was set to V. High for some reason.
I altered it down to Medium and it ran straight away.
Brilliant!!!!

Thanks Again.






Similar Threads
Thread Thread Starter Forum Replies Last Post
calling to xlam macro from macro inside xlsb SteveB Excel VBA 0 June 30th, 2008 06:43 PM
Yes to duplicates MMJiggy62 Beginning VB 6 3 July 14th, 2006 11:51 AM
duplicates and unique sheba0907 SQL Language 6 July 3rd, 2006 02:43 PM
checking for duplicates jammykam Access 3 October 2nd, 2003 08:06 PM
Duplicates ashley_y Access 11 August 14th, 2003 03:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.