PDA

View Full Version : placing muliple checkboxes



trippo
03-03-2010, 07:34 AM
I have a code that places checkboxes in 60 consecutive cells of a column. As the checkboxes are placed, the first checkbox is aligned in the cell, but as the others are placed down the column, the checkboxes start to wander out of the cell such that the last checkbox is no longer in the last cell location (somewhat below).

I have tried to use the activecell .top and .left commands, but that doesn't work (even if I select the last cell location, it will place the checkbox below the row). I have tried to calculate the position in inches based on the number of rows and their heights and that doesn't work (it's almost like the row heights are not as large as indicated).

Thoughts?

'Make sure all rows and columns are the correct height and width as the check boxes are added based upon the cell height and width.
Header1 = 15.75
Header2 = 24#
HeightRow = 18#
Column1 = 35#
Column2 = 7.5
Column3 = 11#
Column4 = 12#
WidthColumn = 16#

Range("A1:A1").EntireRow.RowHeight = Header1
Range("A2:A2").EntireRow.RowHeight = Header2
Range("A3:A3").EntireRow.RowHeight = Header1
Range("A4:A4").EntireRow.RowHeight = Header1
Range("A5:A" & FinalRow).EntireRow.RowHeight = HeightRow


Columns(1).ColumnWidth = Column1
Columns(2).ColumnWidth = Column2
Columns(3).ColumnWidth = Column3
Columns(4).ColumnWidth = Column4
DataColumn = 5
Do Until DataColumn = FinalColumn
Columns(DataColumn).ColumnWidth = WidthColumn
DataColumn = DataColumn + 1
Loop

'Insert a column to the left of the selected/input column
Range(InputColumnInsert & "1", InputColumnInsert & "1").EntireColumn.Insert

'Start inserting checkboxes after the heading rows.This assumes the first checkbox row is in row number 5.
ChkBxLocation = "71.25"
For RowNum = 5 To FinalRow
'Select the first cell of the range to insert the check box.
Range(InputColumnInsert & RowNum).Select

'Determine the pixel locatin to insert the check box. All check boxes locations will be determined this way.
ChkBxLocation = Header2 + (Header1 * 3) + 2 + (HeightRow * (RowNum - 5))

ActiveSheet.CheckBoxes.Add(Left:=ActiveCell.Left + 30, Top:=ActiveCell.Top, Width:=24#, Height:=17.25).Select
'add a check box with the box checked = false - not checked.
With Selection
.Value = xlOn
.LinkedCell = ActiveCell.Address
.Display3DShading = True
.Value = xlOff
End With
'remove checkbox text
Selection.Characters.Text = ""

'make the font transparent
Range(ActiveCell.Address).Select
Selection.NumberFormat = ";;;"

Next RowNum

CreganTur
03-03-2010, 08:13 AM
I think you wanted to put this in the Excel Help section and put it here in the Access Help section by mistake.

Why are you creating these checkboxes with code instead of designing them into the spreadsheet? What's the purpose of this?

trippo
03-03-2010, 08:35 AM
I tried to put it in the excel section, but it ended up here in the access forum.

But I don't understand your question. I need to add columns to the spread sheet once in a while and wanted to have the checkboxes available and linked to the cell. What dod you mean by "designing them into the spreadsheet"?