View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Simon Lloyd[_1171_] Simon Lloyd[_1171_] is offline
external usenet poster
 
Posts: 1
Default Option Button in User Form


levtweeney;407954 Wrote:
Hi all

I am creating a user form to add data to a spreadsheet. I have set up
text boxes to add this data and then move on to the next line ready for
new data (This works). I also need to allow this to happen when a user
selects an option box (Male or Female).

I have create a frame (Frame1) and placed two option boxes within this
frame, one called optMale and the other optFemale, these have also been
grouped.

This is the code I currently have on my command button, which allows me
to add the data to the spreadsheet but I need to add the gender for each
row from these option boxes. Any help would be most appreciated.


Code:
--------------------

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'copy the data to the Spreadsheet
ws.Cells(iRow, 1).Value = Me.houseNo.Value
ws.Cells(iRow, 2).Value = Me.streetName.Value
ws.Cells(iRow, 3).Value = Me.Town.Value
ws.Cells(iRow, 4).Value = Me.postCode.Value

'clear the data
Me.houseNo.Value = ""
Me.streetName.Value = ""
Me.Town.Value = ""
Me.postCode.Value = ""


End Sub

--------------------
Welcome to The Code Cage!, i am assuming you have checkbooxes for male

or female?

Code:
--------------------
If Me.CheckBox1.Value = True Then
Range("A1").Value = "Male"
ElseIf Me.CheckBox2.Value = True Then
Range("A1").Value = "Female"
End If
--------------------
naturally you would change Range("A1") for ws.Cells(iRow, x).Value where
x would be your next location


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=113703