Hello,
I am fairly new to coding so may not be aware of an easier way to do this, but the gist of my problem is that I am trying to have the user input an integer that I have declared as an integer x. Everything works fine if the user inputs an integer but in the case where they put in anything but an integer or hit cancel you'd get a type mismatch error. I've read many threads on restricting a user to integer entry but haven't found anything that solves the cancel problem, as on cancel it returns FALSE and gives a type mismatch error. So now I have resorted to pulling my hair out, as this is for now only being used by me but I'd like to make this macro easy to use for the average user. Any help would be greatly appreciated. I'll include some sample code from the Sub to let you know exactly what I am dealing with.
Function Parse()
Dim y As Integer, x As Integer
lastrow = ActiveSheet.UsedRange.Rows.Count
lastcol = ActiveSheet.UsedRange.Columns.Count
x = InputBox(Prompt:="Select column to parse:", Title:="Column Select", Default:="1")
If x = vbNullString Then End
For y = lastrow To 2 Step -1
Call TestParse(y, x)
Next y
End Function
Function TestParse(y As Integer, x As Integer)
Dim icount As Integer, i As Integer
Dim lnum As String, lword As String
lastcol = ActiveSheet.UsedRange.Columns.Count
For icount = Len(Cells(y, x)) To 1 Step -1
If IsNumeric(Mid(Cells(y, x), icount, 1)) Then
i = i + 1
lnum = Mid(Cells(y, x), icount, 1) & lnum
Else
lword = Mid(Cells(y, x), icount, 1) & lword
End If
If i = 1 Then lnum = CInt(Mid(lnum, 1, 1))
Next icount
Cells(y, (lastcol - 1)) = CLng(lnum)
Cells(y, lastcol) = lword
End Function
Nick
Bookmarks