Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Compile error :Duplicate declaration in current scope

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    38
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    this s part of a larger formula:

    Dim c
    For Each c In Range("C1:C" & x)
    If c = "" Then
    MsgBox "Please enter data in cell " & c.Address
    c.Select
    Exit Sub
    End If

    Dim x As Integer, counter As Integer, y As Integer, MyArr
    Randomize
    MyArr = Array(4, 8, 16, 32, 64, 128, 256)


    when i try and execute the macro i get this message "Compile error : Duplicate declaration in current scope". And also the line "Dim x as Interger" get highlited.
    How should i stop this from happening?


    [ This Message was edited by: MERKY on 2002-05-02 10:54 ]

  2. #2
    Board Regular
    Join Date
    Apr 2002
    Location
    Greenwood, SC
    Posts
    677
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You need to dimension x before you use it.
    Plus, it's a good practice to do all of your dimension at the beginning of the program.

    The reason for this is that the first time you refer to x, VBA dimensions it as a variant type. So when you dimension it again later, it gives an error.

    K

  3. #3
    Board Regular
    Join Date
    Apr 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    you could also try declaring you var's like so:

    Dim var1, var2, var3 as integer

    Also the variable "Counter" you have listed may be a built in function so hence "Duplicate Declaration in Scope" Not 100% sure about that but try "Coun1" or something different.

    Regards and good luck!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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