Reputation: 23
I searched for solutions on the web for my problem, but couldn't find them. When running the following, I get the error: Invalid outside procedure for the second line. Does anyone have suggestions how to solve this? Thank you.
Dim i As Integer
For i = 1 To 37918
If Sheets("nw").Cells(i, 1).Value = Cells(6, 3).Value And Sheets("nw").Celss(i, 2) > Sheets("nw").Cells(i, 2).Value Then Sheets("nw").Cells(15, 22).Value = Sheets("nw").Cells(i, 3).Value
End If
Next i
End Sub
Sub NewCost()
End Sub
Also, when I place Sub NewCost()
above Dim i as integer
I get the error:
end if without block if
Upvotes: 2
Views: 303
Reputation: 10715
Your For loop is outside the Sub()
Try this:
Option Explicit
Sub NewCost()
Dim i As Long
For i = 1 To 37918
With Sheets("nw")
If .Cells(i, 1) = .Cells(6, 3) And .Celss(i, 2) > .Cells(i, 2) Then
.Cells(15, 22) = .Cells(i, 3)
End If
End With
Next
End Sub
Upvotes: 1
Reputation: 3960
The max value for an Integer is ~32767. You have to pick a different data type if you want your counter to be that high (perhaps a long?)
Upvotes: 3