Duplicate declaration in current scope

serenomoreno3

New Member
Joined
Oct 9, 2021
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
So I'm taking a civil engineering course and the teacher is teaching us some coding.
Not getting deep into the subject of the class, i'm trying to run this code but I keep getting a "Duplicate declaration in current scope" and keep getting the first line of the code in yellow.

I don't know how coding works and the one I wrote is based on what the teacher made. Any help to understand/fix this would be appreciated.



Sub Linea_Influencia()
Dim P, L As Double
Dim x(10), b(20), x(10, 10), M(10, 10) As Double

P = Worksheets("Lineas de Influencia").Cells(2, 2).Value
L = Worksheets("Lineas de Influencia").Cells(3, 2).Value

For i = 0 To 10
a(i) = i / 10 * L
b(i) = L - a(i)
Next i

For i = 0 To n
For j = 0 To 10
x(j) = j / 10 * L

If x(j) <= a(i) Then
V(i, j) = P * b(i) / L
M(i, j) = P * b(i) * x(j) / L
Else
V(i, j) = P * b(i) / L - P
M(i, j) = P * b(i) / L - P * (x(j) - a(i))
End If

Next j

Next i

For i = 0 To 10
Worksheets("Lineas de Influencia").Cells(10 + i, 1).Value = a(i)
Worksheets("Lineas de Influencia").Cells(25 + i, 1).Value = x(i)
Next i

For i = 0 To 10
For j = 0 To 10
Worksheets("Lineas de Influencia").Cells(10 + j, 2 + i).Value = V(i, j)
Worksheets("Lineas de Influencia").Cells(25 + K, 2 + i).Value = M(i, j)
Next j

Next i

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You have declared x tweice
Rich (BB code):
Dim x(10), b(20), x(10, 10), M(10, 10) As Double
 
Upvote 0
Welcome to the MrExcel board!

Dim P, L As Double
Just another coding point. Here you have only declared L as Double. Without a specific type, P will be a Variant. If you want them both to be Double you need
VBA Code:
Dim P As Double, L As Double

It is a similar situation in your second Dim line.
 
Upvote 0

Forum statistics

Threads
1,224,876
Messages
6,181,519
Members
453,050
Latest member
Obil

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