Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Checkboxes and Captions Not Able to Return Value

Hi all.

I am currently working on a user form and want a cell to return a value based on the status of the checkbox(true or false). However, I have 30 Checkboxes to loop through (10 sets of Yes, No and NA) so I was wondering if I could do this dynamically. Here is the code I have so far, but it keeps getting stuck on the Controls("CheckBoxYes" & i).Caption:

Private Sub CommandButton1_Click()
Dim emptyRow As Long
Dim CriteriaAnswerYes As Control
Dim CriteriaAnswerNo As Control
Dim CriteriaAnswerNA As Control

Dim i As Long


For i = 1 To 10

Set CriteriaAnswerYes = Controls("CheckBoxYes" & i)
Set CriteriaAnswerNo = Controls("CheckBoxNo" & i)
Set CriteriaAnswerNA = Controls("CheckBoxNA" & i)

If CriteriaAnswerYes.Value = True And CriteriaAnswerNo.Value = True Then
MsgBox "Please only select one value from the checkboxes!", vbCritical
Exit Sub
ElseIf CriteriaAnswerYes.Value = True And CriteriaAnswerNA.Value = True Then
MsgBox "Please only select one value from the checkboxes!", vbCritical
Exit Sub
ElseIf CriteriaAnswerNo.Value = True And CriteriaAnswerNA.Value = True Then
MsgBox "Please only select one value from the checkboxes!", vbCritical
Exit Sub

Else
If CriteriaAnswerYes.Value = True Then
Cells(emptyRow, i + 6).Value = CriteriaAnswerYes.Caption
ElseIf CriteriaAnswerNo.Value = True Then
Cells(emptyRow, i + 6).Value = CriteriaAnswerNo.Caption
ElseIf CriteriaAnswerNA.Value = True Then
Cells(emptyRow, i + 6).Value = CriteriaAnswerNA.Caption
End If
End If
Next i

End Sub


Thank you in advance.

Cheers.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Checkboxes and Captions Not Able to Return Value

Perhaps you could use 3 listbox controls and name them appropriately...

lstYes
lstNo
lstNa

...and set MultiSelect and ListStyle to 1. Then all you need to do is
query each listbox listitem's value.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
Return value(s) based on selected checkboxes Nikki Excel Worksheet Functions 5 May 7th 07 03:48 PM
Return value based on checkboxes selected -- IF() LOOKUP() William Horton Excel Worksheet Functions 3 April 17th 07 07:56 PM
checkboxes' return value Helmut Weber[_2_] Excel Programming 1 March 13th 07 11:29 PM
Help:Programmatically Adding Checkboxes with Captions [email protected] Excel Programming 2 April 19th 06 08:09 PM
"Reading" Excel VBA checkboxes and their captions Eliezer Excel Programming 5 September 9th 04 02:30 AM


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