Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Simple VB code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cjupiter - 24 Jan 2006 13:50 GMT
Hi,

Im trying to write a simple macro with a checkbox, so when i click a
checkbox a number is added to another number. So for example when i select a
checkbox i want the number 5 to be added to a number in another cell on my
spreadsheet.

Thankyou
Tom Ogilvy - 24 Jan 2006 14:22 GMT
Place a checkbox from the control toolbox toolbar

double click on the checkbox and it will take you to the Click event

Private Sub CheckBox1_Click()

End Sub

You can put your code here:

Private Sub CheckBox1_Click()
if not isnumeric(Range("A1").Value) then exit sub
if CheckBox1.Value = True then
  Range("A1").Value = Range("A1").Value + 5
else
  Range("A1").Value = Range("A1").Value - 5
end if
End Sub

Adjust the code to perform the functionality you actually require.

No go back to excel and in the control toolbox toolbar, make sure the button
in the upper left hand corner is not depressed (take you out of design
mode).

Signature

Regards,
Tom Ogilvy

> Hi,
>
[quoted text clipped - 4 lines]
>
> Thankyou
Kev - 24 Jan 2006 14:26 GMT
Try this

If CheckBox1.Value = True Then
Range("A1").Value = (Range("a1").Value + Range("a2").Value)
End If

First place a checkbox called checkbox1 in your sheet, double click on
the box and insert this snip of code. You can change the range values to
suit or change the range prior to the equals sign to place the result in
another cell.

Regards Kev
cjupiter - 25 Jan 2006 01:08 GMT
Thanks guys. Much helpful :)

> Hi,
>
[quoted text clipped - 4 lines]
>
> Thankyou
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.