View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
[email protected] jamasm2010@gmail.com is offline
external usenet poster
 
Posts: 33
Default Checkbox Quandry

On Tuesday, June 14, 2016 at 11:24:43 AM UTC-5, Peter T wrote:
wrote in message
I have a spreadsheet with a number of non-contiguous checkboxes (forms
control) in column A. Section headings break up the sequence. In column B,
there is a description associated with each checkbox. I need to be able to
check the status of the checkboxes - if checked, copy the description to a
new sheet. If no checkbox is found, then print the section heading and
continue. The snippet below is as far as I can get before I run into
problems. Any help would be greatly appreciated.

LastRow = curWks.Cells(curWks.Rows.Count, 2).End(xlUp).Row
For iRow = 3 To LastRow
For Each myCBX In curWks.CheckBoxes
If myCBX.Value = xlOn Then
curWks.Cells(iRow, 2).Copy
Destination:=Worksheets("Sheet1").Cells(xCntr + 1, 1)
xCntr = xCntr + 1
End If
Next myCBX
Next iRow


===============================

Couple of comments at just a glance of your code and without testing
anything

Remove the iRow loop, it doesn't relate to the checkboxes so you're
repeating the same the checkbox loop multiple times.

Get the relevant row and column from the TopLeftCell of the given myCBX
object, eg
rowIdx = myCBX.TopLeftCell.Row
colIdx = myCBX.TopLeftCell.Column

You might want to check the position, ie TopLeftCell, is in the appropriate
cell range, or between 3 and LastRow, and if so do the copy stuff. Though
rather than "Copy" simply do rngDest.Value = rngSource.Value unless you also
want the formats

Peter T


Here is how I incorporated what you advised for me.

For Each myCBX In curWks.CheckBoxes
colIdx = myCBX.TopLeftCell.Column
rowIdx = myCBX.TopLeftCell.Row

If myCBX.Value = xlOn Then
curWks.Cells(rowIdx, colIdx).Offset(0, 1).Copy Destination:=Worksheets("Sheet1").Cells(xCntr + 1, 1)
Debug.Print rowIdx
xCntr = xCntr + 1
End If
Next myCBX

Originally, I had a checkbox on line 3, but subsequently added a checkbox on line 2, because I wanted the section header (there are 4 headers) printed and each of the standards selected (checkboxes) to go under that header. When I debug it, line 3 still shows up first and line 1 (not line 2) shows up at the very bottom. Obviously, I'm not doing something correctly!
James