Compile error :Duplicate declaration in current scope

MERKY

New Member
Joined
Apr 29, 2002
Messages
38
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
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top