LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default linked cell to change another cell

First, I would use the checkbox from the Forms toolbar--not the checkbox from
the Control Toolbox toolbar.

Each of the checkboxes from the Forms toolbar could have the same macro assigned
to it.

Here are two routines. The first lays out checkboxes from the forms toolbar in
C3:C10. That's a one time only routine (or rerun when you need to).

The second routine is the one that does the work when you click the checkboxes.

Option Explicit
Sub LayOutCheckboxes()

Dim myCBX As CheckBox
Dim myCell As Range
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
.CheckBoxes.Delete 'nice for testing
For Each myCell In .Range("C3:C10").Cells
With myCell
Set myCBX = .Parent.CheckBoxes.Add _
(Top:=.Top, Width:=.Width, _
Left:=.Left, Height:=.Height)
With myCBX
.LinkedCell = myCell.Offset(0, -2).Address(external:=True)
.Caption = ""
.Name = "CBX_" & myCell.Address(0, 0)
.OnAction = "'" & ThisWorkbook.Name & "'!CbxClick"
End With
End With
Next myCell
End With
End Sub
Sub CBXClick()

Dim myCBX As CheckBox

With ActiveSheet
Set myCBX = .CheckBoxes(Application.Caller)
If myCBX.Value = xlOff Then
.Cells(myCBX.TopLeftCell.Row, "B").ClearContents
End If
End With
End Sub

Brettjg wrote:

I have a checkbox linked to cell A1. In the cell B1 I have a number which
could be (say) 1 or 2. When the checkbox is "unchecked" and therefore A1 =
FALSE I want to clear the contents of B1. I can't do it by a formula in B1
because the number has been entered manually.

The best way I can think of is to run a macro when checkbox is clicked, and
if A1 = FALSE then clearcontents of B1, but how do I refer to the linked cell
for the particular checkbox in the macro? This same macro would be run for up
to 50 checkboxes all in column "A" so I could just refer to the cell by
Cell("A" & rownum).Offset(0, 1) but how do I find out what 'rownum' is for
the checkbox that has been clicked please?

Regards, Brett


--

Dave Peterson
 
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
How do I have a linked cell auto-size to fit the linked data? CristinPDX Excel Discussion (Misc queries) 0 June 24th 08 08:42 PM
Listbox linked cell does not change Dkline Excel Worksheet Functions 2 May 5th 07 03:57 PM
How to force a cell value to change if Linked cell moves? EagleOne Excel Discussion (Misc queries) 2 December 6th 06 03:32 PM
how do i record changing cell data (cell is dde linked) Morph Excel Discussion (Misc queries) 1 September 22nd 05 12:28 AM
Change sheet name on linked cell by dropdown box Mikeice Excel Worksheet Functions 12 June 11th 05 08:45 AM


All times are GMT +1. The time now is 07:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"