#1   Report Post  
Dave_2k5
 
Posts: n/a
Default For Each Fuction???


I am buliding a questionnaire using Excel and I am using option buttons
and text boxs. I want to have a reset button which changes all the
option button values to false and the text boxes to nothing ("").

I don't want to have a really long code, One line for each option
button, as there are over 50 option buttons.

I have had a look at trying to do a For Each Statement, but couldn't
get it to work...Please Help!!!

Cheers,

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile: http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=389835

  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Dim btn As OptionButton
Dim txt As TextBox
For Each btn In ActiveSheet.OptionButtons
btn.Value = False
Next btn

For Each txt In ActiveSheet.TextBoxes
txt.Text = ""
Next txt

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dave_2k5" wrote in
message ...

I am buliding a questionnaire using Excel and I am using option buttons
and text boxs. I want to have a reset button which changes all the
option button values to false and the text boxes to nothing ("").

I don't want to have a really long code, One line for each option
button, as there are over 50 option buttons.

I have had a look at trying to do a For Each Statement, but couldn't
get it to work...Please Help!!!

Cheers,

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile:

http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=389835



  #3   Report Post  
Dave_2k5
 
Posts: n/a
Default


Bob,

I have tried what you said, but when I press the button it doesn't do
anything, not even an error message...What I'm I doing wrong??? I am
using Excel 2000 would this affect anything??

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile: http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=389835

  #5   Report Post  
Dave_2k5
 
Posts: n/a
Default


This is as it is written exactly in my code:

Private Sub reset_btn_Click()

Dim btn As optionbutton
Dim txt As TextBox
For Each btn In ActiveSheet.OptionButtons
btn.Value = False
Next btn

For Each txt In ActiveSheet.TextBoxes
txt.text = ""
Next txt


Range("C123,C127,C131").Select
Selection.Value = "Choose..."
Activewindow.ScrollRow = 1

End Sub

I put it in like this from the start and it still does nothing!!

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile: http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=389835



  #6   Report Post  
Dave_2k5
 
Posts: n/a
Default


This is as it is written exactly in my code:

Private Sub reset_btn_Click()

Dim btn As optionbutton
Dim txt As TextBox
For Each btn In ActiveSheet.OptionButtons
btn.Value = False
Next btn

For Each txt In ActiveSheet.TextBoxes
txt.text = ""
Next txt


Range("C123,C127,C131").Select
Selection.Value = "Choose..."
Activewindow.ScrollRow = 1

End Sub

I put it in like this from the start and it still does nothing!!

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile: http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=389835

  #7   Report Post  
Dave_2k5
 
Posts: n/a
Default


This is as it is written exactly in my code:

Private Sub reset_btn_Click()

Dim btn As optionbutton
Dim txt As TextBox
For Each btn In ActiveSheet.OptionButtons
btn.Value = False
Next btn

For Each txt In ActiveSheet.TextBoxes
txt.text = ""
Next txt


Range("C123,C127,C131").Select
Selection.Value = "Choose..."
Activewindow.ScrollRow = 1

End Sub

I put it in like this from the start and it does nothing!!

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile: http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=389835

  #8   Report Post  
Norman Jones
 
Posts: n/a
Default

Hi Dave,

If the OptionButtons and TextBoxes are from the Control Toolbox. try:

'=========================
Private Sub reset_btn_Click()

Dim oleObj As OLEObject

For Each oleObj In ActiveSheet.OLEObjects
If TypeOf oleObj.Object Is MSforms.OptionButton Then
oleObj.Object.Value = False
ElseIf TypeOf oleObj.Object Is MSforms.TextBox Then
oleObj.Object.Value = ""
End If
Next

End Sub
'<<=========================

---
Regards,
Norman



"Dave_2k5" wrote in
message ...

This is as it is written exactly in my code:

Private Sub reset_btn_Click()

Dim btn As optionbutton
Dim txt As TextBox
For Each btn In ActiveSheet.OptionButtons
btn.Value = False
Next btn

For Each txt In ActiveSheet.TextBoxes
txt.text = ""
Next txt


Range("C123,C127,C131").Select
Selection.Value = "Choose..."
Activewindow.ScrollRow = 1

End Sub

I put it in like this from the start and it does nothing!!

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile:
http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=389835



  #9   Report Post  
Bob Phillips
 
Posts: n/a
Default

Is it a userform

Private Sub reset_btn_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.OptionButton Then
ctl.Value = False
ElseIf TypeOf ctl Is MSForms.TextBox Then
ctl.Text = ""
End If
Next ctl


Range("C123,C127,C131").Select
Selection.Value = "Choose..."
ActiveWindow.ScrollRow = 1

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dave_2k5" wrote in
message ...

This is as it is written exactly in my code:

Private Sub reset_btn_Click()

Dim btn As optionbutton
Dim txt As TextBox
For Each btn In ActiveSheet.OptionButtons
btn.Value = False
Next btn

For Each txt In ActiveSheet.TextBoxes
txt.text = ""
Next txt


Range("C123,C127,C131").Select
Selection.Value = "Choose..."
Activewindow.ScrollRow = 1

End Sub

I put it in like this from the start and it does nothing!!

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile:

http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=389835



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
Insert Fuction cfraley Excel Worksheet Functions 3 May 11th 05 08:36 PM
IF fuction and format ... MJK700i Excel Worksheet Functions 3 April 24th 05 11:57 AM
Page Number Fuction ChrisA Excel Discussion (Misc queries) 1 February 17th 05 08:58 PM
how can I exceed the nested if fuction limit mgdye Excel Discussion (Misc queries) 5 January 30th 05 02:09 PM
how can I exceed the nested if fuction limit Mike Excel Discussion (Misc queries) 0 January 30th 05 12:17 AM


All times are GMT +1. The time now is 05:09 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"