Dec 14 2020 12:01 AM - edited Dec 14 2020 12:02 AM
need help with part of vba code
If Me.cmbWeek.ListIndex > -1 Then
Set Ws = Worksheets(Me.cmbWeek.Value)
Else: MsgBox "INCORRECT INPUT." & vbNewLine & "Use Dropdown For Listed Weeks.", vbCritical, "INPUT ERROR"
cmbWeek.SelStart = 0
cmbWeek.SelLength = cmbWeek.TextLength
Exit Sub
End If
I not sure what do to change the code?
all the rest code is good in that selection
Thanks You
Dec 14 2020 02:45 AM
The code refers to a combo box named cmbWeek, but there is no combo box on the userform.
Delete the part of the code shown in your post (from If to End If)
Dec 14 2020 06:42 AM
delete whole selection I mean an do not put anything or for new code?
Dec 14 2020 01:20 PM
Yes, simply select that part and press Delete. You don't have to replace it with anything.
Dec 15 2020 07:03 AM
Dec 15 2020 11:49 AM
Which line causes that error?
Dec 15 2020 02:50 PM
Dec 16 2020 12:43 AM
In the On Click event procedure of CommandButton1 on UserForm1, you declare G and R as Byte. A variable of type Byte can only have values in the range of 0 to 255. So the loop
For G = 18 To 1000
will cause G to become too large. Change both G and R to Long.
However, it still won't work. You refer to Controls("TextBox1" & G) etc., but your userform does not have text boxes TextBox118 to TextBox11000.
What are you trying to do?
Dec 16 2020 12:44 PM
Dec 16 2020 01:01 PM
You can't have thousands of text boxes on a userform, so you will have to explain much more clearly what you want to do.
Dec 16 2020 02:28 PM
Dec 16 2020 02:36 PM
I'm afraid that makes no sense. You'll have to explain what you want to do in the loop.
Filling thousands of text boxes is not a realistic option.
Dec 16 2020 02:52 PM
The form is for to input data in into worksheet
Date
Description
Withdrawl
Desposit
next for loop
that code i have is in a loop but not working go make work please
Dec 16 2020 03:15 PM
You don't want to loop! It makes no sense whatsoever. Try this code:
Private Sub CommandButton1_Click()
Dim r As Long
If Not IsDate(Me.TextBox1) Then
Me.TextBox1.SetFocus
MsgBox "Please enter a valid date!", vbExclamation
Exit Sub
End If
If Me.TextBox2 = "" Then
Me.TextBox2.SetFocus
MsgBox "Please enter a description!", vbExclamation
Exit Sub
End If
If Me.TextBox3 = "" And Me.TextBox4 = "" Then
Me.TextBox3.SetFocus
MsgBox "Please enter a withdrawal and/or a deposit!", vbExclamation
Exit Sub
End If
r = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & r).Value = Me.TextBox1.Value
Range("B" & r).Value = Me.TextBox2.Value
Range("I" & r).Value = Me.TextBox3.Value
Range("J" & r).Value = Me.TextBox4.Value
Unload Me
End Sub
Dec 17 2020 12:01 AM
Thanks You very much the code works good I let my friend later today see he thinks of it