Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Create/copy combo boxes in one range if condition is met in a different range

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Create/copy combo boxes in one range if condition is met in adifferent range

One way:

Option Explicit
Sub testme01()

Dim myOLEObj As OLEObject
Dim myRng As Range
Dim myCell As Range

With ActiveSheet
Set myRng = .Range("b22:b33")
End With

For Each myCell In myRng.Cells
With myCell
If IsEmpty(.Offset(0, -1)) Then
'done.
Exit For
Else
Set myOLEObj = .Parent.OLEObjects.Add _
(ClassType:="Forms.ComboBox.1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, Top:=.Top, Width:=.Width, _
Height:=.Height)
End If
End With

With myOLEObj
.Object.BackColor = &HFFFF&
.LinkedCell = .TopLeftCell.Address(external:=True)
.ListFillRange = Worksheets("Linked Cells") _
.Range("g2:g9").Address(external:=True)
.Placement = xlMoveAndSize
End With

Next myCell

End Sub


LB wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Create/copy combo boxes in one range if condition is met in a different range

Thanks for your prompt reply. I've copied your code into my macro.
The yellow highlighting part worked great, but it's still copying the
combo box next to every cell even if it's blank. I have another macro
that runs first that puts the following formula into the respective
cells in column A then hardcodes the values to get rid of the formulas
that didn't bring back a result:

Range("A23").Select
Selection.FormulaArray = _

"=IF(R20C=""Closed"","""",IF(iserror(INDEX(Range2, SMALL(IF(Range1=Name&R20C,ROW(Schedules!R1:R77)),R OW(Schedules!R[-22])),4)),"""",INDEX(Range2,SMALL(IF(Range1=Name&Temp late!R20C,ROW(Schedules!R1:R77)),ROW(Schedules!R[-22])),4)))"
Range("A23").Select
Application.CutCopyMode = False
Selection.Copy
Range("A23,C23,E23,G23,I23"). _
Select
Range("i23").Activate
ActiveSheet.Paste
Rows("23:23").Select
Selection.Copy
Range("A24:A34").Select
ActiveSheet.Paste

Rows("23:34").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

It doesn't seem to be recognizing the blank cells in column A. Please
help!!!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Create/copy combo boxes in one range if condition is met in adifferent range

First, I read the posts in plain text--I connect to the newsservers
directly--not through excelforum.

Second, your cells that evaluated to "" and were converted to values aren't
blank!

Try using:
=ISBLANK(A1)
(and point at one of those cells)

But you can check for the length of what's in the cell.

This is the line that would change:

If IsEmpty(.Offset(0, -1)) Then
to
if .offset(0,-1).value = "" then

====
Ps. When I really have to have empty cells for those "" converted to values,
I'll do this:

Select the range
edit|replace
what: (leave blank)
with: $$$$$
replace all

then reverse it:
edit|replace
what: $$$$$
with: (leave blank)
replace all

It means that the cell is now really blank. (Test it with =isblank().)


LB wrote:

Thanks for your prompt reply. I've copied your code into my macro.
The yellow highlighting part worked great, but it's still copying the
combo box next to every cell even if it's blank. I have another macro
that runs first that puts the following formula into the respective
cells in column A then hardcodes the values to get rid of the formulas
that didn't bring back a result:

Range("A23").Select
Selection.FormulaArray = _

"=IF(R20C=""Closed"","""",IF(iserror(INDEX(Range2, SMALL(IF(Range1=Name&R20C,ROW(Schedules!R1:R77)),R OW(Schedules!R[-22])),4)),"""",INDEX(Range2,SMALL(IF(Range1=Name&Temp late!R20C,ROW(Schedules!R1:R77)),ROW(Schedules!R[-22])),4)))"
Range("A23").Select
Application.CutCopyMode = False
Selection.Copy
Range("A23,C23,E23,G23,I23"). _
Select
Range("i23").Activate
ActiveSheet.Paste
Rows("23:23").Select
Selection.Copy
Range("A24:A34").Select
ActiveSheet.Paste

Rows("23:34").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

It doesn't seem to be recognizing the blank cells in column A. Please
help!!!!


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Create/copy combo boxes in one range if condition is met in a different range

Thanks so much, Dave, for the prompt replies and the great advice.
Most everything works like a charm now. I'm struggling to find the
perfect code to be able to send my file via e-mail without getting a
warning that Outlook Express is blocking a potentially unsafe
attachment. I'll start a new thread for this problem, though! Thanks
again, Dave.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Combo boxes to change options based on other Combo boxes. Ancient Wolf New Users to Excel 1 March 27th 09 06:29 PM
RANGE EXCEL copy cell that meets criteria in a range confused Excel Worksheet Functions 3 March 27th 08 01:41 PM
How do I create dependent combo-boxes? ExcelDave Excel Discussion (Misc queries) 3 November 20th 06 02:26 PM
Programmatically create combo boxes Richard[_31_] Excel Programming 1 August 12th 04 03:10 AM
Using SUM with worksheet range selected by two combo boxes fifthhorseman Excel Programming 1 June 18th 04 10:38 PM


All times are GMT +1. The time now is 09:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"