Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Checkbox and linkedcell question

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checkbox and linkedcell question

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Checkbox and linkedcell question

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
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
Checkbox Question slow386 Excel Discussion (Misc queries) 7 July 21st 07 12:06 AM
Checkbox Question MCrum Excel Discussion (Misc queries) 1 January 15th 07 12:38 PM
Checkbox question Patrick Simonds Excel Programming 6 July 31st 05 05:49 PM
CheckBox question Sheldon Excel Programming 6 January 25th 05 05:11 PM
Setting LinkedCell on a CheckBox Control scottrell Excel Programming 2 July 30th 04 11:06 PM


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