PC Review


Reply
Thread Tools Rate Thread

Checkbox name linked to a cell

 
 
Tdp
Guest
Posts: n/a
 
      23rd Oct 2008
How do I link a checkbox to a cell so that when the cell is renamed it also
changes the name in the checkbox?
--
Tdp
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Oct 2008
You could use an event macro that looks for a change to a particular cell and
then reacts to that typing change.

If you want to try, then rightclick on the worksheet that owns both the checkbox
and the cell that changes the caption name. Select view code and paste this
into the newly opened code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then
Exit Sub 'one cell at a time
End If

If Intersect(Target, Me.Range("a1")) Is Nothing Then
Exit Sub
End If

'a checkbox from the Forms toolbar
Me.CheckBoxes("Check box 1").Caption = Target.Value

'a checkbox from the control toolbox toolbar
Me.CheckBox1.Caption = Target.Value

End Sub

I included sample code for both types of checkboxes (from the Forms toolbar and
from the Control toolbox toolbar).

You'll want to delete the code you don't need and make sure the checkbox names
are correct.

Tdp wrote:
>
> How do I link a checkbox to a cell so that when the cell is renamed it also
> changes the name in the checkbox?
> --
> Tdp


--

Dave Peterson
 
Reply With Quote
 
Tdp
Guest
Posts: n/a
 
      23rd Oct 2008
Thanks Dave,
Whilst I was waiting I tried different ways and came up with this one,
Is there anything wrong with the following?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

UserForm1.CheckBox2.Caption = Worksheets("Sheet4").Range("C4").Value
UserForm1.CheckBox3.Caption = Worksheets("Sheet4").Range("C5").Value

End Sub

--
Tdp


"Dave Peterson" wrote:

> You could use an event macro that looks for a change to a particular cell and
> then reacts to that typing change.
>
> If you want to try, then rightclick on the worksheet that owns both the checkbox
> and the cell that changes the caption name. Select view code and paste this
> into the newly opened code window:
>
> Option Explicit
> Private Sub Worksheet_Change(ByVal Target As Range)
> If Target.Cells.Count > 1 Then
> Exit Sub 'one cell at a time
> End If
>
> If Intersect(Target, Me.Range("a1")) Is Nothing Then
> Exit Sub
> End If
>
> 'a checkbox from the Forms toolbar
> Me.CheckBoxes("Check box 1").Caption = Target.Value
>
> 'a checkbox from the control toolbox toolbar
> Me.CheckBox1.Caption = Target.Value
>
> End Sub
>
> I included sample code for both types of checkboxes (from the Forms toolbar and
> from the Control toolbox toolbar).
>
> You'll want to delete the code you don't need and make sure the checkbox names
> are correct.
>
> Tdp wrote:
> >
> > How do I link a checkbox to a cell so that when the cell is renamed it also
> > changes the name in the checkbox?
> > --
> > Tdp

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Oct 2008
This is on a userform?

Do you need to change the caption that often? With each change of selection?

I would either use the the userform_initialize event to pick up the non-changing
value or if the userform is shown non-modally, then I'd use the worksheet_change
event.




Tdp wrote:
>
> Thanks Dave,
> Whilst I was waiting I tried different ways and came up with this one,
> Is there anything wrong with the following?
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>
> UserForm1.CheckBox2.Caption = Worksheets("Sheet4").Range("C4").Value
> UserForm1.CheckBox3.Caption = Worksheets("Sheet4").Range("C5").Value
>
> End Sub
>
> --
> Tdp
>
> "Dave Peterson" wrote:
>
> > You could use an event macro that looks for a change to a particular cell and
> > then reacts to that typing change.
> >
> > If you want to try, then rightclick on the worksheet that owns both the checkbox
> > and the cell that changes the caption name. Select view code and paste this
> > into the newly opened code window:
> >
> > Option Explicit
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > If Target.Cells.Count > 1 Then
> > Exit Sub 'one cell at a time
> > End If
> >
> > If Intersect(Target, Me.Range("a1")) Is Nothing Then
> > Exit Sub
> > End If
> >
> > 'a checkbox from the Forms toolbar
> > Me.CheckBoxes("Check box 1").Caption = Target.Value
> >
> > 'a checkbox from the control toolbox toolbar
> > Me.CheckBox1.Caption = Target.Value
> >
> > End Sub
> >
> > I included sample code for both types of checkboxes (from the Forms toolbar and
> > from the Control toolbox toolbar).
> >
> > You'll want to delete the code you don't need and make sure the checkbox names
> > are correct.
> >
> > Tdp wrote:
> > >
> > > How do I link a checkbox to a cell so that when the cell is renamed it also
> > > changes the name in the checkbox?
> > > --
> > > Tdp

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Tdp
Guest
Posts: n/a
 
      23rd Oct 2008
The caption may change now and then, but I`m after the ability to change the
checkbox caption. The code I try seems to work at the moment, but what I'm
worried about if it can lead to some problems if the code is not complete?
--
Tdp


"Dave Peterson" wrote:

> This is on a userform?
>
> Do you need to change the caption that often? With each change of selection?
>
> I would either use the the userform_initialize event to pick up the non-changing
> value or if the userform is shown non-modally, then I'd use the worksheet_change
> event.
>
>
>
>
> Tdp wrote:
> >
> > Thanks Dave,
> > Whilst I was waiting I tried different ways and came up with this one,
> > Is there anything wrong with the following?
> >
> > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> >
> > UserForm1.CheckBox2.Caption = Worksheets("Sheet4").Range("C4").Value
> > UserForm1.CheckBox3.Caption = Worksheets("Sheet4").Range("C5").Value
> >
> > End Sub
> >
> > --
> > Tdp
> >
> > "Dave Peterson" wrote:
> >
> > > You could use an event macro that looks for a change to a particular cell and
> > > then reacts to that typing change.
> > >
> > > If you want to try, then rightclick on the worksheet that owns both the checkbox
> > > and the cell that changes the caption name. Select view code and paste this
> > > into the newly opened code window:
> > >
> > > Option Explicit
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > If Target.Cells.Count > 1 Then
> > > Exit Sub 'one cell at a time
> > > End If
> > >
> > > If Intersect(Target, Me.Range("a1")) Is Nothing Then
> > > Exit Sub
> > > End If
> > >
> > > 'a checkbox from the Forms toolbar
> > > Me.CheckBoxes("Check box 1").Caption = Target.Value
> > >
> > > 'a checkbox from the control toolbox toolbar
> > > Me.CheckBox1.Caption = Target.Value
> > >
> > > End Sub
> > >
> > > I included sample code for both types of checkboxes (from the Forms toolbar and
> > > from the Control toolbox toolbar).
> > >
> > > You'll want to delete the code you don't need and make sure the checkbox names
> > > are correct.
> > >
> > > Tdp wrote:
> > > >
> > > > How do I link a checkbox to a cell so that when the cell is renamed it also
> > > > changes the name in the checkbox?
> > > > --
> > > > Tdp
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Oct 2008
Why not just change the caption when the userform loads?

Option Explicit
Private Sub UserForm_Initialize()
Me.CheckBox2.Caption = Worksheets("Sheet4").Range("C4").Value
Me.CheckBox3.Caption = Worksheets("Sheet4").Range("C5").Value
End Sub

Or am I missing something?

Tdp wrote:
>
> The caption may change now and then, but I`m after the ability to change the
> checkbox caption. The code I try seems to work at the moment, but what I'm
> worried about if it can lead to some problems if the code is not complete?
> --
> Tdp
>
> "Dave Peterson" wrote:
>
> > This is on a userform?
> >
> > Do you need to change the caption that often? With each change of selection?
> >
> > I would either use the the userform_initialize event to pick up the non-changing
> > value or if the userform is shown non-modally, then I'd use the worksheet_change
> > event.
> >
> >
> >
> >
> > Tdp wrote:
> > >
> > > Thanks Dave,
> > > Whilst I was waiting I tried different ways and came up with this one,
> > > Is there anything wrong with the following?
> > >
> > > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> > >
> > > UserForm1.CheckBox2.Caption = Worksheets("Sheet4").Range("C4").Value
> > > UserForm1.CheckBox3.Caption = Worksheets("Sheet4").Range("C5").Value
> > >
> > > End Sub
> > >
> > > --
> > > Tdp
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > You could use an event macro that looks for a change to a particular cell and
> > > > then reacts to that typing change.
> > > >
> > > > If you want to try, then rightclick on the worksheet that owns both the checkbox
> > > > and the cell that changes the caption name. Select view code and paste this
> > > > into the newly opened code window:
> > > >
> > > > Option Explicit
> > > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > > If Target.Cells.Count > 1 Then
> > > > Exit Sub 'one cell at a time
> > > > End If
> > > >
> > > > If Intersect(Target, Me.Range("a1")) Is Nothing Then
> > > > Exit Sub
> > > > End If
> > > >
> > > > 'a checkbox from the Forms toolbar
> > > > Me.CheckBoxes("Check box 1").Caption = Target.Value
> > > >
> > > > 'a checkbox from the control toolbox toolbar
> > > > Me.CheckBox1.Caption = Target.Value
> > > >
> > > > End Sub
> > > >
> > > > I included sample code for both types of checkboxes (from the Forms toolbar and
> > > > from the Control toolbox toolbar).
> > > >
> > > > You'll want to delete the code you don't need and make sure the checkbox names
> > > > are correct.
> > > >
> > > > Tdp wrote:
> > > > >
> > > > > How do I link a checkbox to a cell so that when the cell is renamed it also
> > > > > changes the name in the checkbox?
> > > > > --
> > > > > Tdp
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
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
Checkbox linked to calcs MK Microsoft Excel Programming 0 1st Mar 2010 10:24 AM
3 option boxes to linked cell-linked cell to be 1,2,3. Paula Microsoft Excel Programming 1 29th Oct 2009 01:43 PM
CheckBox / Linked Cell Problem Joyce Microsoft Excel Programming 16 28th Sep 2009 01:47 PM
checkbox linked to a cell Greg Microsoft Excel Discussion 1 8th Nov 2006 10:02 PM
checkbox linked to a cell Greg Microsoft Excel Programming 1 8th Nov 2006 10:02 PM


Features
 

Advertising
 

Newsgroups
 


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