VBAの問題です。入力ボタンを押すと、入力した名前と日付が別シートの名前列と日付列の一番下に追記されていくようにしたいのですが上手くいきません。どこが間違ってますか。' 履歴シートに入力された名前と日付を追加 Dim ws As Worksheet Dim nextRow As Long Set ws = Worksheets(\u0026quot;履歴シート\u0026quot;) ' ★出力先シート名 ' B列(名前)の最終行 → 次の行に追加 nextRow = ws.Cells(ws.Rows.count, \u0026quot;B\u0026quot;).End(xlUp).Row + 1 ' データ出力 ws.Cells(nextRow, \u0026quot;B\u0026quot;).Value = targetName ws.Cells(nextRow, \u0026quot;C\u0026quot;).Value = inputDate ' 罫線を引く(B列~C列) With ws.Range(\u0026quot;B\u0026quot; \u0026amp; nextRow \u0026amp; \u0026quot;:C\u0026quot; \u0026amp; nextRow).Borders .LineStyle = xlContinuous .Weight = xlThin End With

1件の回答

回答を書く

1038680

2026-06-05 17:55

+ フォロー

やりたいことが今一つわからないので憶測です。





Sub 入力()

Dim c As Range

For Each c In Range(\u0026quot;C7\u0026quot;, \u0026quot;D7\u0026quot;)

If Trim(c) = \u0026quot;\u0026quot; Then

MsgBox c.Address(0, 0) \u0026amp; \u0026quot; が未入力です。入力してください。\u0026quot;, vbExclamation

Exit Sub

End If

Next c



Dim x As Variant, targetName As String, inputDate As Date

targetName = Range(\u0026quot;D7\u0026quot;).Value

inputDate = Range(\u0026quot;C7\u0026quot;).Value

x = Application.Match(Range(\u0026quot;D7\u0026quot;), Range(\u0026quot;G7:G1000\u0026quot;), 0)

If IsError(x) Then

MsgBox \u0026quot;名前:\u0026quot; \u0026amp; Range(\u0026quot;D7\u0026quot;) \u0026amp; \u0026quot; は一覧にありません\u0026quot;, vbCritical

Exit Sub

End If



Dim nextRow As Long

Cells(x + 6, \u0026quot;I\u0026quot;) = inputDate

Cells(x + 6, \u0026quot;H\u0026quot;) = Cells(x + 6, \u0026quot;H\u0026quot;) + 1

With Worksheets(\u0026quot;履歴シート\u0026quot;)

nextRow = .Cells(Rows.Count, \u0026quot;B\u0026quot;).End(xlUp).Row + 1

.Cells(nextRow, \u0026quot;B\u0026quot;) = targetName

.Cells(nextRow, \u0026quot;C\u0026quot;) = inputDate

.Cells(nextRow, \u0026quot;B\u0026quot;).Resize(, 2).Borders.LineStyle = True

End With



MsgBox \u0026quot;更新が完了しました\u0026quot;, vbInformation



End Sub

うったえる有益だ(0シェアするブックマークする

関連質問

Copyright © 2026 AQ188.com All Rights Reserved.

博識 著作権所有