Additions to userform

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,199
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I have made a userform but need a couple of additions that im not to be about.

The code in use is shown below.

The addition would be that once i press Command Button 1 it should make sure that TextBox 1,2,3,4,5,6 & Option Button1,2,3 has been answered otherwise show msgbox to advise question not answered etc.

The last addition would then be once the above has been successfully transfered to my sheet the text boxes / option buttons should be cleared & focus set on text box 1 ready for the next entry.



Code:
Private Sub CommandButton1_Click()

LastRow = ThisWorkbook.Worksheets("POSTAGE").Cells(Rows.Count, 1).End(xlUp).Row


ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 1).Value = TextBox1.Text


ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 2).Value = TextBox2.Text


ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 3).Value = TextBox3.Text


ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 5).Value = TextBox4.Text


ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 6).Value = TextBox5.Text


ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 9).Value = TextBox6.Text




If OptionButton1.Value = True Then
ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 8).Value = "DR"
End If


If OptionButton2.Value = True Then
ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 8).Value = "IVY"
End If


If OptionButton3.Value = True Then
ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 8).Value = "N/A"
End If




End Sub

Have a nice day.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
PC

Can you upload your file so i can then download and try
 
Upvote 0
Remove the testing:
These lines of code and see if things work:
Code:
For i = 1 To 6
        If Me.Controls("TextBox" & i).Value = "" Then MsgBox "Some Textbox is empty": Exit Sub
    Next
    
    For i = 1 To 3
        If Me.Controls("OptionButton" & i).Value = False Then x = x + 1
    Next
    If x = 3 Then MsgBox "No Option Button is selected": Exit Sub
 
Upvote 0
Ok
That code has been removed.
I then leave 1 text box empty and hit the transfer button.
I see RTE 424 object required.

No matter which text box i leave empty the same line when i debug is shown in yellow

.Cells(lastrow + 1, 6).Value = TextBox5.Text

Transfer goes ahead but there is no values transfered from option button or TextBox6

If i leave a option button unselected then same error message,same line of code in yellow,also button option & TextBox6 no values transfered.

Hope this helps
 
Upvote 0
I only added the part of the script where you wanted to check to make sure no data was missing.

Was this script you provided working before for you?

What version on Excel are you using?
 
Upvote 0
So here is the line of code I provided:
.Cells(lastrow + 1, 9).Value = TextBox6.Text: TextBox6.Value = ""

You tell me why this would not work?

You said Value from textbox6 was not working.

This script says put textbox6 value into column 9
 
Upvote 0
I spent time helping on this but for some reason it seems like my efforts did not help. I setup a Userform just like you showed and it all worked for me.
 
Upvote 0
Regarding post #15 i am only advising you what happens once i run the code with your code removed in post # 13

Why it doesnt work i dont know & yes TextBox 6 then is entered into column 9
 
Upvote 0
I admit I get confused when I write a script that works perfect for me but user says it does not work for them.

So I'm a little lost what does and does not work.

If the only part that is not working is the part where it checks the controls for values I could write that part another way.

But I'm not sure what is and is not working.
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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