I have a friend that need help with vab code

Iron Contributor

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

14 Replies

@sf49ers19238597 

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)

@Hans Vogelaar 

delete whole selection I mean an do not put anything or for new code?

@sf49ers19238597 

Yes, simply select that part and press Delete. You don't have to replace it with anything.

@Hans Vogelaar 

 

 

I remove that slection give me runtime error 6 overflow

@sf49ers19238597 

Which line causes that error?

@Hans Vogelaar 

 

I remove that code I posted first post.

 

Thanks You

@sf49ers19238597 

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?

@Hans Vogelaar 

 

how I make it work. i want a loop

 

 

Thanks You

@sf49ers19238597 

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.

@Hans Vogelaar 

 

ony change code for userform1 to make it work want a loop

@sf49ers19238597 

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.

@Hans Vogelaar 

 

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

 

@sf49ers19238597 

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

@Hans Vogelaar 

 

 

Thanks You very much the code works good I let my friend later today see he thinks of it