'=============================================================================
'- ADD SEVERAL COMBOBOXES TO A WORKSHEET TO SIMULATE DATA VALIDATION
'- NB. used 'On Error Resume Next' to stop message
'- "Object doesn't support this property or method"
'- but this does not seem to affect anything.
'- Brian Baulsom July 2007 using Excel 2000
'==============================================================================
Sub ADD_COMBOBOXES()
Dim ToRow As Long
Dim MyCell As Range
'--------------------------------------------------------------------------
'- worksheet
With ActiveSheet.Cells
.Font.Name = "Arial"
.Font.Size = 8
.Columns(1).ColumnWidth = 20
.Rows.RowHeight = 15
End With
'---------------------------------------------------------------------------
'- TO TRAP UNEXPLAINED ERROR MSG
On Error Resume Next
'---------------------------------------------------------------------------
'- Add ComboBoxes
For ToRow = 2 To 10
Set MyCell = ActiveSheet.Cells(ToRow, 1)
'- Add Combobox
With ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1")
.Name = "CB" & CStr(ToRow)
.ListFillRange = "$J$1:$J$10"
.Placement = xlMoveAndSize
.LinkedCell = MyCell.Address
.Left = MyCell.Left
.Top = MyCell.Top
.Width = MyCell.Width
.Height = MyCell.Height
.MatchRequired = True
.ListRows = 10
End With
Next
'---------------------------------------------------------------------------
MsgBox ("Done")
End Sub
'--------------------------------------------------------------------------------