Userform Initialize

Benwin

New Member
Joined
Mar 24, 2010
Messages
5
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?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
K, I found my answer. Figured I would post it in case anyone else gets this kind of error.

My problem was with the line

cCount = Cells(x,y).Value

It should have read

cCount.Text = Cells(x,y).Value
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,451
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top