N
Neil Pearce
I have previously been kindly provided with code to automatically add combo
boxes to a workbook (see below).
However I now wish to amend the code so that the range for the combo boxes
input are on a different tab. I can not get the right Syntax for this to
work correctly. I wonder if some one could amend correctly please, thank-you.
The troublesome line is:
= .Parent.Range(Back-Up Data!"I7:I24").Address(external:=True)
Kindest of regards,
Neil
Option Explicit
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("D1066")
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(Back-Up
Data!"I7:I24").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
boxes to a workbook (see below).
However I now wish to amend the code so that the range for the combo boxes
input are on a different tab. I can not get the right Syntax for this to
work correctly. I wonder if some one could amend correctly please, thank-you.
The troublesome line is:
= .Parent.Range(Back-Up Data!"I7:I24").Address(external:=True)
Kindest of regards,
Neil
Option Explicit
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("D1066")
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(Back-Up
Data!"I7:I24").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