L
LB
Based on your excellent advice, I was able to use the code below to
create a macro to create/copy combo boxes in the range B22:B33.
However, I only need to have the combo box show up in column B if there
is data in the same row in column A. In other words, if column A same
row is blank, then I need the macro to stop.
1. What is the code to do this conditional execution?
2. I also want the background color of these combo boxes to be yellow.
What code do I need to insert into my existing code to do that?
Thanks in advance for your assistance.
Dim myOLEObj As OLEObject
Dim myRng As Range
Dim myCell As Range
With ActiveSheet
Set myRng = .Range("b22:b33")
For Each myCell In myRng.Cells
With myCell
Set myOLEObj = .Parent.OLEObjects.Add _
(ClassType:="Forms.ComboBox.1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, Top:=.Top, Width:=.Width, _
Height:=.Height)
End With
With myOLEObj
.LinkedCell = .TopLeftCell.Offset(0, 0) _
.Address(external:=True)
.ListFillRange = Worksheets("Linked Cells").Range
("g2:g9") _
.Address(external:=True)
.Placement = xlMoveAndSize
End With
Next myCell
End With
create a macro to create/copy combo boxes in the range B22:B33.
However, I only need to have the combo box show up in column B if there
is data in the same row in column A. In other words, if column A same
row is blank, then I need the macro to stop.
1. What is the code to do this conditional execution?
2. I also want the background color of these combo boxes to be yellow.
What code do I need to insert into my existing code to do that?
Thanks in advance for your assistance.
Dim myOLEObj As OLEObject
Dim myRng As Range
Dim myCell As Range
With ActiveSheet
Set myRng = .Range("b22:b33")
For Each myCell In myRng.Cells
With myCell
Set myOLEObj = .Parent.OLEObjects.Add _
(ClassType:="Forms.ComboBox.1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, Top:=.Top, Width:=.Width, _
Height:=.Height)
End With
With myOLEObj
.LinkedCell = .TopLeftCell.Offset(0, 0) _
.Address(external:=True)
.ListFillRange = Worksheets("Linked Cells").Range
("g2:g9") _
.Address(external:=True)
.Placement = xlMoveAndSize
End With
Next myCell
End With