I have a friend that need help with vab code

%3CLINGO-SUB%20id%3D%22lingo-sub-1984521%22%20slang%3D%22en-US%22%3EI%20have%20a%20friend%20that%20need%20help%20with%20vab%20code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1984521%22%20slang%3D%22en-US%22%3E%3CP%3Eneed%20help%20with%20part%26nbsp%3B%20of%20vba%20code%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EIf%20Me.cmbWeek.ListIndex%20%26gt%3B%20-1%20Then%0A%20%20%20%20Set%20Ws%20%3D%20Worksheets(Me.cmbWeek.Value)%0A%20%20%20%20%20%20%20%20%20Else%3A%20MsgBox%20%22INCORRECT%20INPUT.%22%20%26amp%3B%20vbNewLine%20%26amp%3B%20%22Use%20Dropdown%20For%20Listed%20Weeks.%22%2C%20vbCritical%2C%20%22INPUT%20ERROR%22%0A%20%20%20%20%20%20%20%20%20cmbWeek.SelStart%20%3D%200%0A%20%20%20%20%20%20%20%20%20cmbWeek.SelLength%20%3D%20cmbWeek.TextLength%0A%20%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20End%20If%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20not%20sure%20what%20do%20to%20change%20the%20code%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eall%20the%20rest%20code%20is%20good%20in%20that%20selection%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20You%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1984521%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1984919%22%20slang%3D%22en-US%22%3ERe%3A%20I%20have%20a%20friend%20that%20need%20help%20with%20vab%20code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1984919%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F322399%22%20target%3D%22_blank%22%3E%40sf49ers%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20code%20refers%20to%20a%20combo%20box%20named%20cmbWeek%2C%20but%20there%20is%20no%20combo%20box%20on%20the%20userform.%3C%2FP%3E%0A%3CP%3EDelete%20the%20part%20of%20the%20code%20shown%20in%20your%20post%20(from%20If%20to%20End%20If)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1985459%22%20slang%3D%22en-US%22%3ERe%3A%20I%20have%20a%20friend%20that%20need%20help%20with%20vab%20code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1985459%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Edelete%20whole%20selection%20I%20mean%20an%20do%20not%20put%20anything%20or%20for%20new%20code%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1986883%22%20slang%3D%22en-US%22%3ERe%3A%20I%20have%20a%20friend%20that%20need%20help%20with%20vab%20code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1986883%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F322399%22%20target%3D%22_blank%22%3E%40sf49ers%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYes%2C%20simply%20select%20that%20part%20and%20press%20Delete.%20You%20don't%20have%20to%20replace%20it%20with%20anything.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1989142%22%20slang%3D%22en-US%22%3EiRe%3A%20I%20have%20a%20friend%20that%20need%20help%20with%20vab%20code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1989142%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20remove%20that%20slection%20give%20me%20runtime%20error%206%20overflow%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1990744%22%20slang%3D%22en-US%22%3ERe%3A%20iRe%3A%20I%20have%20a%20friend%20that%20need%20help%20with%20vab%20code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1990744%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F322399%22%20target%3D%22_blank%22%3E%40sf49ers%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhich%20line%20causes%20that%20error%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1991313%22%20slang%3D%22en-US%22%3ERe%3A%20iRe%3A%20I%20have%20a%20friend%20that%20need%20help%20with%20vab%20code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1991313%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20remove%20that%20code%20I%20posted%20first%20post.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20You%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional 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

@sf49ers 

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?

@sf49ers 

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

@sf49ers 

Which line causes that error?

@Hans Vogelaar 

 

I remove that code I posted first post.

 

Thanks You

@sf49ers 

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

@sf49ers 

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

@sf49ers 

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

 

@sf49ers 

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