+ Reply to Thread
Results 1 to 9 of 9

Duplicate declaration in current scope

  1. #1
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Duplicate declaration in current scope

    In a macro i created i want a macro to preform similar actions on more than
    one sheet. I put it all in one macro (string is the same, just the worksheetname different, but it now gives me the error:

    "Duplicate declaration in current scope"

    What can i do about it?

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Duplicate declaration in current scope

    The macro needs changing, post the code - remember to use Code Tags
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Duplicate declaration in current scope

    Hi,

    Instead of declaring the variable with a Dim statement in every procedure, define the variable as a Public variable i.e. Public stSheetName as String, and put this outside any procedures as the top of a Module.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Duplicate declaration in current scope

    Hold on: Here it goes:

    (when it gives the comment, the debug mode automatically selects the rule:
    "Dim Found0 as range")

    Please Login or Register  to view this content.
    Last edited by Turbobiker; 10-30-2009 at 09:58 AM.

  5. #5
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Duplicate declaration in current scope

    Please Login or Register  to view this content.
    Sorry, it's to long to post in one post
    Last edited by Turbobiker; 10-30-2009 at 09:59 AM.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Duplicate declaration in current scope

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  7. #7
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Duplicate declaration in current scope

    talked it over with my supervisor and he would like each product to have theyr own Macro.

    But because we have about 15 products i don't want to make 15 buttons.
    Is there a way to make them follow up automaticly? (without pressing the button again)??

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Duplicate declaration in current scope

    Yes - just have another macro that calls them all - for example:
    Please Login or Register  to view this content.
    replacing Macro1 with the name of your first macro, and so on.
    Note: if all of your macros basically do the same thing but with slight variations, your code can probably be made a lot more efficient, but we would need to see it.
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Duplicate declaration in current scope

    If the actions are similar, then I would think that one macro could easily be enough. It's just a case of declaring variables usually. Howvwer, without an example workbook that's the best you will get

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1