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
Thanks, Peter, that worked quite well, however I'm not able to get a hold of the section headings and copy them over.
James
|