PC Review


Reply
Thread Tools Rate Thread

Checkbox and linkedcell question

 
 
treesinger101
Guest
Posts: n/a
 
      24th Dec 2009
I want to use the cell address of a checkbox's linked cell. How do I
reference it in VBA so I don't have to write the code over and over. I have
the location hardcoded now, but I have about 30 checkboxes.

Here is what I want to happen when I click any checkbox.

Private Sub TTWK1_Click()

If Cells(3, 2).Value = True Then
Cells(3, 1) = "=NOW()"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Else
Cells(3, 1) = ""
End If
End Sub

Thank you for any help.
--
Athena
Payroll Goddess
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      24th Dec 2009
I wouldn't bother.

I'd just check(!) the checkbox itself.

Private Sub TTWK1_Click()
If me.ttwk1.value = true then
'....



treesinger101 wrote:
>
> I want to use the cell address of a checkbox's linked cell. How do I
> reference it in VBA so I don't have to write the code over and over. I have
> the location hardcoded now, but I have about 30 checkboxes.
>
> Here is what I want to happen when I click any checkbox.
>
> Private Sub TTWK1_Click()
>
> If Cells(3, 2).Value = True Then
> Cells(3, 1) = "=NOW()"
> Selection.Copy
> Selection.PasteSpecial Paste:=xlPasteValues
> Application.CutCopyMode = False
> Else
> Cells(3, 1) = ""
> End If
> End Sub
>
> Thank you for any help.
> --
> Athena
> Payroll Goddess


--

Dave Peterson
 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      24th Dec 2009
Hi Athena,

Further to what Dave has said, there is also no need to create a formula in
the cell and then copy and past the values. You can do it in one line with
the following code.

Cells(3, 1) = Now()

I can't say it will save you much but you can also place the majority of the
code in a standard module and call that module from each of the checkbox
click events and pass the checkbox and row number parameters as follows. (It
is more applicable where you have a lot of code that is all the same for each
checkbox)

The checkbox code would be like the following. The 3 parameter in
Call UpdateNow(chkBox, 3) is the row number where you want the value to be
placed.
Private Sub TTWK1_Click()
Dim chkBox As Object
Set chkBox = Me.TTWK1
Call UpdateNow(chkBox, 3)
End Sub

The following code would then be in a standard module.
Sub UpdateNow(chk As Object, rowNumb As Long)
If chk.Value = True Then
Cells(rowNumb, 1) = Now()
Else
Cells(rowNumb, 1) = ""
End If
End Sub

--
Regards,

OssieMac


"treesinger101" wrote:

> I want to use the cell address of a checkbox's linked cell. How do I
> reference it in VBA so I don't have to write the code over and over. I have
> the location hardcoded now, but I have about 30 checkboxes.
>
> Here is what I want to happen when I click any checkbox.
>
> Private Sub TTWK1_Click()
>
> If Cells(3, 2).Value = True Then
> Cells(3, 1) = "=NOW()"
> Selection.Copy
> Selection.PasteSpecial Paste:=xlPasteValues
> Application.CutCopyMode = False
> Else
> Cells(3, 1) = ""
> End If
> End Sub
>
> Thank you for any help.
> --
> Athena
> Payroll Goddess

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LinkedCell sarndt Microsoft Excel Programming 2 15th Mar 2010 03:45 PM
Re: linkedcell property Bernard Liengme Microsoft Excel Programming 0 23rd Dec 2008 09:17 PM
LinkedCell problem TFriis Microsoft Excel Programming 4 27th Nov 2007 12:30 PM
Master-Detail Datagrid -checkbox (once tick the checkbox, all the child checkbox is ticked) Agnes Microsoft VB .NET 0 16th Aug 2004 11:23 AM
Setting LinkedCell on a CheckBox Control scottrell Microsoft Excel Programming 2 30th Jul 2004 11:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:06 PM.