S Oberlander
Board Regular
- Joined
- Nov 25, 2020
- Messages
- 147
- Office Version
- 365
- Platform
- Windows
See below code to check for the existence of "mid". My problem is that "mid" is a whole number, and vba is picking up "C" as a scientific number, effectively triggering the MsgBox and Exit Sub regardless if a match is found or not.
How can I have vba pick up "C" as a whole number?
How can I have vba pick up "C" as a whole number?
VBA Code:
Sub findmid()
Dim lastrow As Long
Dim mid As Variant
Dim C As Range
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
mid = Application.InputBox("Enter mid or select cell containing the mid.", "Analyze it")
For Each C In Range("$B$2:$B$" & lastrow)
If C.Value = mid = False Then
MsgBox "Invalid Mid or Mid not found!", vbOKOnly, "Analyze it"
Exit Sub
End If
Exit For
Next C
End Sub