Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Lin Lin is offline
external usenet poster
 
Posts: 10
Default Looping Checkboxes in Worksheet

Hi
I have a set of checkboxes in worksheet. I am using the following code to
get the value of the checkbox if it's checked. But Some how it is not working
at all. I am not getting error either.

Dim k As Integer
Dim CH(1 To 5) As Object
Set CH(1) = CH1
Set CH(2) = CH2
Set CH(3) = CH3
Set CH(4) = CH4
Set CH(5) = CH5


For k = 1 To 5
With Worksheets("Sheet1")
If CH(k).Value = True Then
Worksheets("Sheet2").[A2] = CH(k).Caption
Else
Worksheets("Sheet2").[A2] = " "
End If
End With
Next k
Any help really appreciate
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Looping Checkboxes in Worksheet

Checkboxes from the Forms or Control Toolbox menu

Is the code in a normal module or the sheet module with the checkboxes

Regards,
Peter T

"Lin" wrote in message
...
Hi
I have a set of checkboxes in worksheet. I am using the following code to
get the value of the checkbox if it's checked. But Some how it is not
working
at all. I am not getting error either.

Dim k As Integer
Dim CH(1 To 5) As Object
Set CH(1) = CH1
Set CH(2) = CH2
Set CH(3) = CH3
Set CH(4) = CH4
Set CH(5) = CH5


For k = 1 To 5
With Worksheets("Sheet1")
If CH(k).Value = True Then
Worksheets("Sheet2").[A2] = CH(k).Caption
Else
Worksheets("Sheet2").[A2] = " "
End If
End With
Next k
Any help really appreciate
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
Lin Lin is offline
external usenet poster
 
Posts: 10
Default Looping Checkboxes in Worksheet

Checkboxes are in the Control Toolbox.
Code is in Normal module

"Peter T" wrote:

Checkboxes from the Forms or Control Toolbox menu

Is the code in a normal module or the sheet module with the checkboxes

Regards,
Peter T

"Lin" wrote in message
...
Hi
I have a set of checkboxes in worksheet. I am using the following code to
get the value of the checkbox if it's checked. But Some how it is not
working
at all. I am not getting error either.

Dim k As Integer
Dim CH(1 To 5) As Object
Set CH(1) = CH1
Set CH(2) = CH2
Set CH(3) = CH3
Set CH(4) = CH4
Set CH(5) = CH5


For k = 1 To 5
With Worksheets("Sheet1")
If CH(k).Value = True Then
Worksheets("Sheet2").[A2] = CH(k).Caption
Else
Worksheets("Sheet2").[A2] = " "
End If
End With
Next k
Any help really appreciate
Thanks




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Looping Checkboxes in Worksheet

In a NEW workbook run test1 and test2

Sub test1()
Dim i As Long
Dim ole As OLEObject
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
ws.Activate
ws.OLEObjects.Delete ' << only on a test sheet !
For i = 1 To 5
Set ole = ws.OLEObjects.Add("Forms.Checkbox.1")
With ws.Cells(i * 3, 2)
ole.Left = .Left
ole.Top = .Top
End With
ole.Name = "CH" & i
ole.Object.Caption = "Check it " & i
ole.Object.Value = i Mod 2
Next
End Sub

Sub test2()
Dim i As Long
Dim r As Range
Dim ws1 As Worksheet, ws2 As Worksheet
Dim ole As OLEObject

Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")

Set r = ws2.Range("A2").Resize(5, 2)

For i = 1 To 5
Set ole = ws1.OLEObjects("CH" & i)
r(i, 1) = ole.Object.Caption
r(i, 2) = IIf(ole.Object.Value, "On", "")
Next
ws2.Activate
End Sub

Regards,
Peter T


"Lin" wrote in message
...
Checkboxes are in the Control Toolbox.
Code is in Normal module

"Peter T" wrote:

Checkboxes from the Forms or Control Toolbox menu

Is the code in a normal module or the sheet module with the checkboxes

Regards,
Peter T

"Lin" wrote in message
...
Hi
I have a set of checkboxes in worksheet. I am using the following code
to
get the value of the checkbox if it's checked. But Some how it is not
working
at all. I am not getting error either.

Dim k As Integer
Dim CH(1 To 5) As Object
Set CH(1) = CH1
Set CH(2) = CH2
Set CH(3) = CH3
Set CH(4) = CH4
Set CH(5) = CH5


For k = 1 To 5
With Worksheets("Sheet1")
If CH(k).Value = True Then
Worksheets("Sheet2").[A2] = CH(k).Caption
Else
Worksheets("Sheet2").[A2] = " "
End If
End With
Next k
Any help really appreciate
Thanks






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
Looping through a group of checkboxes asdfasdf Excel Programming 9 October 13th 05 02:04 AM
Looping Checkboxes on Worksheet Robbyn Excel Programming 2 August 7th 05 09:09 PM
Checkboxes to spreadsheet using a looping macro Eddie[_5_] Excel Programming 0 September 8th 04 11:04 AM
Checkboxes on a Shared Worksheet! gr8guy Excel Programming 0 May 6th 04 06:20 AM
Looping checkboxes embedded in worksheet Theresa[_5_] Excel Programming 1 February 27th 04 04:41 AM


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