Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorry about the last ones...And statements with IF's

I am trying to put a function into this user box so that if one of th
textboxes are empty, then nothing gets entered into the sheet. Ca
anyone help? I am stumped. I greatly appreciate it.

Private Sub OK_Click()

'This all happens when OK is clicked.

'if the first textbox is blank, then a message box pops up
'to tell you a value must be entered.

If TextBox1 = "" Then MsgBox "you must enter a name"
Range("a1") = TextBox1.Value


If TextBox2 = "" Then MsgBox "you must enter an age"
Range("a2") = TextBox2.Value


If TextBox3 = "" Then MsgBox "you must enter a gender"
Range("a3") = TextBox3.Value


'clears the text boxes for next use
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""

'sets the cursor in textbox1
TextBox1.SetFocus


'hides the userform when ok is clicked
Me.Hide

End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorry about the last ones...And statements with IF's

trickdos,

The following is code that I came up with, but what you want is rreally
more than what you asked for. This will do as you asked.


Charles

Private Sub CommandButton1_Click()
With UserForm1
If .TextBox1.Value = "" Then
MsgBox " You must enter a name"
..TextBox1.SetFocus
Exit Sub
ElseIf .TextBox2.Value = "" Then
MsgBox " You must enter age"
..TextBox2.SetFocus
Exit Sub
ElseIf .TextBox3.Value = "" Then
MsgBox " You must enter gender"
..TextBox3.SetFocus
Exit Sub
End If
Range("A1").Value = .TextBox1.Text
Range("A2").Value = .TextBox2.Text
Range("A3").Value = .TextBox3.Text
..TextBox1 = ""
..TextBox2 = ""
..TextBox3 = ""
Unload UserForm1
End With
End Sub


---
Message posted from http://www.ExcelForum.com/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum with 2 if's Nadine Excel Worksheet Functions 1 May 6th 10 10:08 PM
Or's with If's Statements Sr Accountant[_2_] Excel Discussion (Misc queries) 6 June 22nd 07 03:18 PM
Too many 'if's! Ben Mehling Excel Discussion (Misc queries) 4 May 11th 07 01:31 PM
Too Many If's Rianne Excel Worksheet Functions 10 March 22nd 07 08:13 PM
IF's karensa Excel Worksheet Functions 4 December 27th 06 10:05 PM


All times are GMT +1. The time now is 11:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"