samarrow11
New Member
- Joined
- Apr 22, 2016
- Messages
- 6
Hello everyone! I am a new guy to excel <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> and I'm trying to figure out this error.Always get the type mismatch error and don't know why.
the error happened in z = Application.Workbooks(2).Worksheets(Sheet1).Cells(q, 1).Value * x
code as followed
Sub samyuan1()
Dim z As Single, x As Single, q As Long, y As Long, ufo As Variant, b As Long
For x = 0.1 To 0.9 Step 0.1
For q = 2 To 101
For y = 2 To 101
z = Application.Workbooks(2).Worksheets(Sheet1).Cells(q, 1).Value * x
ufo = Array(Application.WorksheetFunction.NormSInv(0.01), Application.WorksheetFunction.NormSInv(0.02), Application.WorksheetFunction.NormSInv(0.03), Application.WorksheetFunction.NormSInv(0.04), _
Application.WorksheetFunction.NormSInv(0.05), Application.WorksheetFunction.NormSInv(0.06), Application.WorksheetFunction.NormSInv(0.07), Application.WorksheetFunction.NormSInv(0.08), Application.WorksheetFunction.NormSInv(0.09), _
Application.WorksheetFunction.NormSInv(0.1))
If z < ufo(0) Then
b = 1
Else
b = 0
End If
Dim m As Long
For m = 103 To 111
Cells(12, m).Value = b
Next m
Next y
Next q
Next x
End Sub
the error happened in z = Application.Workbooks(2).Worksheets(Sheet1).Cells(q, 1).Value * x
code as followed
Sub samyuan1()
Dim z As Single, x As Single, q As Long, y As Long, ufo As Variant, b As Long
For x = 0.1 To 0.9 Step 0.1
For q = 2 To 101
For y = 2 To 101
z = Application.Workbooks(2).Worksheets(Sheet1).Cells(q, 1).Value * x
ufo = Array(Application.WorksheetFunction.NormSInv(0.01), Application.WorksheetFunction.NormSInv(0.02), Application.WorksheetFunction.NormSInv(0.03), Application.WorksheetFunction.NormSInv(0.04), _
Application.WorksheetFunction.NormSInv(0.05), Application.WorksheetFunction.NormSInv(0.06), Application.WorksheetFunction.NormSInv(0.07), Application.WorksheetFunction.NormSInv(0.08), Application.WorksheetFunction.NormSInv(0.09), _
Application.WorksheetFunction.NormSInv(0.1))
If z < ufo(0) Then
b = 1
Else
b = 0
End If
Dim m As Long
For m = 103 To 111
Cells(12, m).Value = b
Next m
Next y
Next q
Next x
End Sub