-ChatGPT-
-ChatGPT-4の回答
Sub AddTaxList() Dim wb As Workbook Dim wsBank, wsTax As Worksheet Dim lastRowBank, lastRowTax, i, j As Long Set wb = ThisWorkbook Set wsBank = wb.Worksheets("勘定科目(銀行口座)") Set wsTax = wb.Worksheets("消費税リスト") ' 勘定科目(銀行口座)シートの最終行を取得 lastRowBank = wsBank.Cells(wsBank.Rows.Count, 1).End(xlUp).Row ' 消費税リストシートの最終行を取得 lastRowTax = wsTax.Cells(wsTax.Rows.Count, 1).End(xlUp).Row ' 消費税リストシートのデータをコンマ区切りの文字列に変換 Dim taxList As String taxList = "" For i = 2 To lastRowTax taxList = taxList & wsTax.Cells(i, 1).Value If i < lastRowTax Then taxList = taxList & "," End If Next i ' 勘定科目(銀行口座)シートの1列目にデータがある場合、2列目のセルに消費税リストシートの1列目のデータを含むリストを作成 If lastRowBank >= 2 Then For i = 2 To lastRowBank With wsBank.Cells(i, 2).Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=taxList .IgnoreBlank = True .InCellDropdown = True .ShowInput = True .ShowError = True End With Next i End If End Sub