View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default check and uncheck macro

I'm guessing that the checkbox is placed on a worksheet, right?

What kind of checkbox did you use? A checkbox from the Forms toolbar or a
checkbox from the control toolbox toolbar?

If it's a checkbox from the Forms toolbar:

Option Explicit
Sub testme()
Dim RngToCopy As Range
Dim DestCell As Range
Dim CBX As CheckBox

Set CBX = ActiveSheet.CheckBoxes(Application.Caller)

If CBX.Value = xlOn Then
Set RngToCopy = ActiveSheet.Range("a1:b3")
Else
Set RngToCopy = ActiveSheet.Range("x1:z3")
End If

Set DestCell = ActiveSheet.Range("d1")

RngToCopy.Copy _
Destination:=DestCell
End Sub



If it's a checkbox from the control toolbox toolbar:

Option Explicit
Private Sub CheckBox1_Change()
Dim RngToCopy As Range
Dim DestCell As Range

If Me.CheckBox1.Value = True Then
Set RngToCopy = Me.Range("a1:b3")
Else
Set RngToCopy = Me.Range("x1:z3")
End If

Set DestCell = Me.Range("d1")

RngToCopy.Copy _
Destination:=DestCell
End Sub

wrote:

How can i use the checkbox to use a different macro when it's checked
or
unchecked? In this example: i want to copy paste from one location if
is unchecked and from a different location if is check and I uncheck
the checkbox.
thank you
Pamela


--

Dave Peterson