2023年8月4日金曜日

vba 入力規則ーリストを最大行まで設定する。

vba 入力規則ーリストを設定する。

Sub SetupLISTBOX()
Dim maxRow As Long
    maxRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp) 'A列で最大行を求める場合
    With Range("C2:C" maxRow).Validation
        .Delete
        .Add Type:=xlValidateWholeNumber, _
             Operator:=xlBetween, _
             Formula1:="=Sheet2!$A$2:$A$100"   ’Sheet2にリストの要素あり
    End With
End Sub