PDA

View Full Version : Solved: Type MisMatch!!



Saladsamurai
08-26-2009, 11:32 AM
I know this isn't a 'degugging' forum, but does anyone see anything blatently obvious with this? When I click 'debug' I get the screenshot below the code.

Private Sub CommandButton1_Click()

Dim G, Y, R As Integer
Dim xgg, xgy, xgr, xyg, xyy, xyr, xrg, xry, xrr As Integer

xgg = 0
xgy = 0
xgr = 0
xyg = 0
xyy = 0
xyr = 0
xrg = 0
xry = 0
xrr = 0

G = 0
Y = 0
R = 0


For i = 1 To 25
For j = 1 To 32

If Worksheets(10).Cells(i, j) >= 0.9 Then
If Worksheets(9).Cells(i, j) >= 0.9 Then
xgg = xgg + 1
ElseIf Worksheets(9).Cells(i, j) < 0.9 And Worksheets(9).Cells(i, j) > 0.8 Then
xgy = xgy + 1
ElseIf Worksheets(9).Cells(i, j) <= 0.8 And Worksheets(9).Cells(i, j) <> "" Then
xgr = xgr + 1

G = G + 1

End If
ElseIf Worksheets(10).Cells(i, j) < 9 And Worksheets(10).Cells(i, j) > 0.8 Then
If Worksheets(9).Cells(i, j) >= 0.9 Then
xyg = xyg + 1
ElseIf Worksheets(9).Cells(i, j) < 0.9 And Worksheets(9).Cells(i, j) > 0.8 Then
xyy = xyy + 1
ElseIf Worksheets(9).Cells(i, j) <= 0.8 And Worksheets(9).Cells(i, j) <> "" Then
xyr = xyr + 1

Y = Y + 1
End If

ElseIf Worksheets(10).Cells <= 0.8 And Worksheets(10).Cells(i, j) <> "" Then
If Worksheets(9).Cells(i, j) >= 0.9 Then
xrg = xrg + 1
ElseIf Worksheets(9).Cells(i, j) < 0.9 And Worksheets(9).Cells(i, j) > 0.8 Then
xry = xry + 1
ElseIf Worksheets(9).Cells(i, j) <= 0.8 And Worksheets(9).Cells(i, j) <> "" Then
xrr = xrr + 1

End If

R = R + 1

End If

Next j

Next i


End Sub

debug:

http://i12.photobucket.com/albums/a220/saladsamurai/code.jpg

lucas
08-26-2009, 11:39 AM
type mismatch usually means the object(sheet) can't be found or doesn't exist.

Saladsamurai
08-26-2009, 11:42 AM
Hmmm...The sheets definitely exist.

File attached.

Saladsamurai
08-26-2009, 11:47 AM
Okay. This is horse$hit. All I did was close Excel and reopen; run it again and now I get a "Subscript out of Range" error with no option to debug.:angry2:

Tommy
08-26-2009, 12:22 PM
Worksheets(10).cells is invalid, it should have (i,j) maybe?
OK it should have a column and a row index. :)

Saladsamurai
08-26-2009, 06:24 PM
Worksheets(10).cells is invalid, it should have (i,j) maybe?
OK it should have a column and a row index. :)

You are the man. I am scum. Thank you :beerchug:


(It's amazing how you think you see one thing, but it's really something else. I must have stared at that for 60 full minutes before slamming my keyboard and going home for the day! :rotlaugh:)