Hi Mike,
Here is the code which will create validation in range B3:B6 based on A3:A6.
Sub Macro1()
Dim rg As Range
Set rg = Range("B3:B6")
With rg.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=
_
xlBetween, Formula1:="=$A$3:$A$6"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = True
End With
End Sub
Currently the key point is how to trigger the macro and adjust the range
created the validation.
So when the col A's row number will change.
If the row number will change every time when the Workbook open/close, we
can run the macro in that time.
But if the row rumber may change at any time,
there is an event will fire when any cell in the sheet is changed, and let
us know which range is changed.
So if capture the event and know that A7 is changed we can assume the
result range should be A3:A7.
But that event will fire all the time, even if certain irrevelant cell is
changed(e.g. T56) the event will fire too.
So this all depend your scenario, you may have to design an algorithm based
on concrete scenario.
SheetChange Event
See AlsoApplies ToExampleSpecificsOccurs when cells in any worksheet are
changed by the user or by an external link.
Private Sub object_SheetChange(ByVal Sh As Object, ByVal Source As Range)
object Application or Workbook. For more information about using events
with the Application object, see Using Events with the Application Object.
Sh A Worksheet object that represents the sheet.
Source The changed range.
Remarks
This event doesn't occur on chart sheets.
Example
This example runs when any worksheet is changed.
Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Source As Range)
' runs when a sheet is changed
End Sub
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.