Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Checkboxes from the Forms Toolbar

I looked through the Google Groups posts and the Microsoft Office Discussion
posts, but I just cannot seem to find what I am looking for.

What I would like to do is have a few checkboxes on the main page of my
file: "Date", "Time", "Company". If the user checks any or all of these boxes
before clicking the CommandButton "Go on", some VBA code will fill in cells
a1, a2, and a3 with the date, time, and company name (say "HP"). If some of
the checkmarks on the first sheet are NOT checked, the code will leave the
corresponding cells on the second sheet blank.

Thanks for your response!
cht13er
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Checkboxes from the Forms Toolbar

right click on the checkbox and select assign a macro.

You should an assign it a macro like

Sub EnterDate()
if Activesheet.Checkboxes("Check Box 1").Value = xlOn then
Range("A1").Value = Date
Range("A1").NumberFormat = "MM/DD/YYYY"
end if
End Sub

If you want checking any of the three checkboxes to fill the cells, assign
them all to a single macro that does that

Sub EnterData()
Dim cbox as Checkbox
set cbox = Activesheet.Checkboxes(Application.Caller)
if cbox = xlOn then
Range("A1").Value = Format(Date,"mm/dd/yyyy")
Range("A2").Value = Format(Time,"hh:mm AM/PM")
Range("A3").Value = "HP"
end if
End Sub

You haven't said how one would tell whether the Commandbutton had been click
previously.

--
Regards,
Tom Ogilvy

"cht13er" wrote in message
...
I looked through the Google Groups posts and the Microsoft Office

Discussion
posts, but I just cannot seem to find what I am looking for.

What I would like to do is have a few checkboxes on the main page of my
file: "Date", "Time", "Company". If the user checks any or all of these

boxes
before clicking the CommandButton "Go on", some VBA code will fill in

cells
a1, a2, and a3 with the date, time, and company name (say "HP"). If some

of
the checkmarks on the first sheet are NOT checked, the code will leave the
corresponding cells on the second sheet blank.

Thanks for your response!
cht13er



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Checkboxes from the Forms Toolbar

Thank you, Tom and Dave.

I used the button and checkboxes from the forms toolbar, so I adjusted the
2nd batch of code that Dave supplied, with all the changes here that future
readers might find useful:

_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!
Option Explicit
Sub RunUsingCheckbuttons()

'Declarations
Dim OWks As Worksheet 'This sheet is used to add a line item
Dim NWks As Worksheet 'This sheet stores all the items
Dim NumEntries As Integer 'The total number of entries
'Coolness!
Set OWks = Worksheets("Main Page")
Set NWks = Worksheets("Data")
'Get new number of entries
NumEntries = OWks.Cells(23, 3)
NumEntries = NumEntries + 1
OWks.Cells(23, 3).Value = NumEntries
'See if CheckBoxes are checked, move over data if they are
If OWks.CheckBoxes("Check Box 1").Value = xlOn Then 'First and Last Name
NWks.Cells(NumEntries + 1, 1).Value = OWks.Cells(4, 3).Value
NWks.Cells(NumEntries + 1, 2).Value = OWks.Cells(4, 4).Value
Else
NWks.Cells(NumEntries + 1, 1).Value = "Unknown"
NWks.Cells(NumEntries + 1, 2).Value = "Unknown"
End If
If OWks.CheckBoxes("Check Box 3").Value = xlOn Then 'Date of Birth
NWks.Cells(NumEntries + 1, 3).Value = OWks.Cells(7, 3).Value
Else: NWks.Cells(NumEntries + 1, 3).Value = "Unknown"
End If
If OWks.CheckBoxes("Check Box 4").Value = xlOn Then 'Time
NWks.Cells(NumEntries + 1, 4).Value = OWks.Cells(10, 3).Value
Else: NWks.Cells(NumEntries + 1, 4).Value = "Unknown"
End If
If OWks.CheckBoxes("Check Box 5").Value = xlOn Then 'Company
NWks.Cells(NumEntries + 1, 5).Value = OWks.Cells(13, 3).Value
Else: NWks.Cells(NumEntries + 1, 5).Value = "Unknown"
End If
'Go back to first page
OWks.Cells(1, 1).Select
End Sub
_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!

And once again, I placed this code in a module and assigned the code to a
command button.

What this code now does for me is not very great - none of the cells are
reset...you could even just say "If cells are not "", then move the cell data
over to the next page" - but this was a great way for me to start thinking
about using checkboxes and about how to use commandbuttons properly.

Thanks a tonne for your help, Dave!
--
Chris Togeretz
Ontario, Canada

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
Forms - Checkboxes Jane Excel Worksheet Functions 3 October 3rd 06 02:21 PM
creating checkboxes from forms tool bar KB Excel Worksheet Functions 2 April 25th 06 03:53 AM
Forms control checkboxes on charts Tom Ogilvy Excel Programming 2 September 14th 04 12:35 AM
Excel VBA Forms and multiple checkboxes Francis de Brienne Excel Programming 0 August 25th 04 09:00 PM
Can you hide forms checkboxes Matt Excel Programming 2 January 10th 04 06:32 PM


All times are GMT +1. The time now is 11:01 PM.

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"