Hello everybody. I am busy trying to make a spreadsheet for work that has all user input in multiple userforms. The data should only be numbers and I have setup checks to verify it. The problem I am having is that when the Userform Initializes the check routine gives an error. It works fine if there is no data to pull in but as soon as you place a number for it to capture I get "Run time error '91'. Object variable or With block variable not set. Below is my initialize code
Private Sub Userform_Initialize()
Dim cCount As Control
If Sheets("Forecast").Range("AA1") = 1 Then 'Fri
x = 80
y = 17
Sheets("WeekEnd").Activate
For Each cCount In Me.Controls
If TypeName(cCount) = "TextBox" Then
If y = 20 Then
y = 17
x = x + 1
End If
cCount = Cells(x, y).Value
y = y + 1
End If
Next cCount
Else
x = 80
y = 21
Sheets("WeekEnd").Activate
For Each cCount In Me.Controls
If TypeName(cCount) = "TextBox" Then
If y = 24 Then
y = 21
x = x + 1
End If
cCount = Cells(x, y).Value
y = y + 1
End If
Next cCount
End If
End Sub
and this is the check code;
Private Sub check()
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
End If
End With
End Sub
The error comes from "If Not IsNumeric..." line. Any ideas?
Private Sub Userform_Initialize()
Dim cCount As Control
If Sheets("Forecast").Range("AA1") = 1 Then 'Fri
x = 80
y = 17
Sheets("WeekEnd").Activate
For Each cCount In Me.Controls
If TypeName(cCount) = "TextBox" Then
If y = 20 Then
y = 17
x = x + 1
End If
cCount = Cells(x, y).Value
y = y + 1
End If
Next cCount
Else
x = 80
y = 21
Sheets("WeekEnd").Activate
For Each cCount In Me.Controls
If TypeName(cCount) = "TextBox" Then
If y = 24 Then
y = 21
x = x + 1
End If
cCount = Cells(x, y).Value
y = y + 1
End If
Next cCount
End If
End Sub
and this is the check code;
Private Sub check()
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
End If
End With
End Sub
The error comes from "If Not IsNumeric..." line. Any ideas?