#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 109
Default Combo Box Code

The code below was kindly written for me by Dave Peterson. It fills the
range of cells A1:A30 with combo boxes dependant on an list fill fange Z1:Z5
and offsets the outputs by 1 column. This has proven an extremley useful
tool over the last few months.

I wish to modify the code for a list fill range of Z1:Z5 on "Sheet2", i.e.
another tab, and am stuggling. Any ideas? Help much appreciated.


Kind regards,

Neil


Sub COMBOboxes()

Dim myCell As Range
Dim myRng As Range
Dim myDD As DropDown
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
.DropDowns.Delete 'nice for testing!
Set myRng = .Range("A1:A30")
For Each myCell In myRng.Cells
With myCell
Set myDD = .Parent.DropDowns.Add _
(Top:=.Top, _
Left:=.Left, _
Width:=.Width, _
Height:=.Height)

myDD.ListFillRange _
= .Parent.Range("z1:z5").Address(external:=True)
myDD.LinkedCell = .Offset(0, 1).Address(external:=True)
myDD.LinkedCell = .Offset(0, 1).Address(external:=True)
myDD.ListIndex = 1 '<-- added
End With
Next myCell
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,276
Default Combo Box Code

Hi Neil,

change
Set wks = ActiveSheet by

Set ws = Worksheets("Sheet2")

"Neil Pearce" wrote:

The code below was kindly written for me by Dave Peterson. It fills the
range of cells A1:A30 with combo boxes dependant on an list fill fange Z1:Z5
and offsets the outputs by 1 column. This has proven an extremley useful
tool over the last few months.

I wish to modify the code for a list fill range of Z1:Z5 on "Sheet2", i.e.
another tab, and am stuggling. Any ideas? Help much appreciated.


Kind regards,

Neil


Sub COMBOboxes()

Dim myCell As Range
Dim myRng As Range
Dim myDD As DropDown
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
.DropDowns.Delete 'nice for testing!
Set myRng = .Range("A1:A30")
For Each myCell In myRng.Cells
With myCell
Set myDD = .Parent.DropDowns.Add _
(Top:=.Top, _
Left:=.Left, _
Width:=.Width, _
Height:=.Height)

myDD.ListFillRange _
= .Parent.Range("z1:z5").Address(external:=True)
myDD.LinkedCell = .Offset(0, 1).Address(external:=True)
myDD.LinkedCell = .Offset(0, 1).Address(external:=True)
myDD.ListIndex = 1 '<-- added
End With
Next myCell
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Combo Box Code

The dropdowns go on the activesheet, but the list to fill those dropdowns is on
Sheet2???

change this:

myDD.ListFillRange _
= .Parent.Range("z1:z5").Address(external:=True)

to

myDD.ListFillRange _
= worksheets("Sheet2").Range("z1:z5").Address(extern al:=True)

The linked cells still go on the same sheet as the dropdowns, right???

Neil Pearce wrote:

The code below was kindly written for me by Dave Peterson. It fills the
range of cells A1:A30 with combo boxes dependant on an list fill fange Z1:Z5
and offsets the outputs by 1 column. This has proven an extremley useful
tool over the last few months.

I wish to modify the code for a list fill range of Z1:Z5 on "Sheet2", i.e.
another tab, and am stuggling. Any ideas? Help much appreciated.

Kind regards,

Neil

Sub COMBOboxes()

Dim myCell As Range
Dim myRng As Range
Dim myDD As DropDown
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
.DropDowns.Delete 'nice for testing!
Set myRng = .Range("A1:A30")
For Each myCell In myRng.Cells
With myCell
Set myDD = .Parent.DropDowns.Add _
(Top:=.Top, _
Left:=.Left, _
Width:=.Width, _
Height:=.Height)

myDD.ListFillRange _
= .Parent.Range("z1:z5").Address(external:=True)
myDD.LinkedCell = .Offset(0, 1).Address(external:=True)
myDD.LinkedCell = .Offset(0, 1).Address(external:=True)
myDD.ListIndex = 1 '<-- added
End With
Next myCell
End With
End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Combo Box Code

myDD.ListFillRange _
=Sheets("Sheet2").Range("z1:z5").Address(external: =True)

Works for me.


Gord Dibben MS Excel MVP

On Mon, 5 Jan 2009 05:57:25 -0800, Neil Pearce
wrote:

The code below was kindly written for me by Dave Peterson. It fills the
range of cells A1:A30 with combo boxes dependant on an list fill fange Z1:Z5
and offsets the outputs by 1 column. This has proven an extremley useful
tool over the last few months.

I wish to modify the code for a list fill range of Z1:Z5 on "Sheet2", i.e.
another tab, and am stuggling. Any ideas? Help much appreciated.


Kind regards,

Neil


Sub COMBOboxes()

Dim myCell As Range
Dim myRng As Range
Dim myDD As DropDown
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
.DropDowns.Delete 'nice for testing!
Set myRng = .Range("A1:A30")
For Each myCell In myRng.Cells
With myCell
Set myDD = .Parent.DropDowns.Add _
(Top:=.Top, _
Left:=.Left, _
Width:=.Width, _
Height:=.Height)

myDD.ListFillRange _
= .Parent.Range("z1:z5").Address(external:=True)
myDD.LinkedCell = .Offset(0, 1).Address(external:=True)
myDD.LinkedCell = .Offset(0, 1).Address(external:=True)
myDD.ListIndex = 1 '<-- added
End With
Next myCell
End With
End Sub


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
Drop down or Combo Box Help with VBA code and formula [email protected] Excel Worksheet Functions 4 July 17th 07 03:03 PM
what is code to activate a combo box in control toolbox Pogo Excel Discussion (Misc queries) 1 July 23rd 06 10:41 AM
Source code for combo box in form shnim1 Excel Discussion (Misc queries) 1 April 14th 06 04:46 AM
combo box on change code frendabrenda1 Excel Discussion (Misc queries) 0 April 10th 06 04:21 PM
Combo Box Code jd815 Excel Discussion (Misc queries) 1 September 14th 05 08:53 PM


All times are GMT +1. The time now is 06:02 AM.

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

About Us

"It's about Microsoft Excel"