I am getting Run error time '13': Type Mismatch on "#DIV/0 value in cell that I have tried to address with my code not to reach this point but the vba skips implementing the first if condition (unloading the userform and exiting this condition) and results in this error over and over again.
The highlighted line in the code for debug is If ws.Cells(iRow, 32) = True Then.
When the value in the cells are #DIV/0, it is normal to get this error but I tried to check beforehand and get out of the condition if this occurs.
The code goes as follows:
If ws.Cells(45, 7) = 1 Then
Dim msg1, button1, title1, response1
msg1 = "Are you sure you don't want to check any of the presented questions? In this case, Contractual factors category will be removed from the evaluation process and the weights will be reallocated."
button1 = vbYesNo + vbDefaultButton2
title1 = "Confirmation Notice"
response1 = MsgBox(msg1, button1, title1)
If response1 = vbYes Then
If ws.Cells(53, 6).Value = 1 Then
MsgBox "No single factor was selected. Thus, there are no results to be evaluated."
Unload Me
Call clear_data
Dashboard.Show
Else
iRow2 = 2
For iRow = 2 To 7
**If ws.Cells(iRow, 32) = True Then**
ws.Cells(iRow2, 38).Value = ws.Cells(iRow, 27)
ws.Cells(iRow2, 39).Value = ws.Cells(iRow, 31)
iRow2 = iRow2 + 1
End If
Next iRow
Unload Me
conf.Show
End If
Else
Exit Sub
End If
Else
iRow2 = 45
For iRow = 45 To 51
If ws.Cells(iRow, 6) = True Then
ws.Cells(iRow2, 9).Value = ws.Cells(iRow, 3)
ws.Cells(iRow2, 10).Value = ws.Cells(iRow, 4)
iRow2 = iRow2 + 1
End If
Next iRow
End If
If ws.Cells(8, 32).Text = "#DIV/0!" Then
Unload Me
Dashboard.Show
ElseIf ws.Cells(8, 32) = 1 Then
iRow2 = 2
For iRow = 2 To 7
If ws.Cells(iRow, 32) = True Then
ws.Cells(iRow2, 38).Value = ws.Cells(iRow, 27)
ws.Cells(iRow2, 39).Value = ws.Cells(iRow, 31)
iRow2 = iRow2 + 1
End If
Next iRow
Unload Me
conf.Show
Else
iRow2 = 2
For iRow = 2 To 7
If ws.Cells(iRow, 32) = True Then
ws.Cells(iRow2, 38).Value = ws.Cells(iRow, 27)
ws.Cells(iRow2, 39).Value = ws.Cells(iRow, 31)
ws.Cells(iRow2, 41).Value = ws.Cells(iRow, 31)
iRow2 = iRow2 + 1
End If
Next iRow
Unload Me
CPIGauge.Show
End If
I would appreciate any help regarding this error.