ご回答いただき、誠にありがとうございます。
ユーザーフォームは変更したい行数を入力して、対象となる行の値をTextBoxに取得させるマクロを最初に実行させるように作りました。
以下がそのマクロ文です。 TextBox1は行番号、TextBox2は会社名、TextBox3以降は会社の住所や電話番号などの情報が入ります。
二つ目のマクロ文は変更前の会社名を同一シート上のZ1、変更後の会社名をZ3に取得させ、それぞれの値を「請求書データベース」AT1及びAT2が参照するようにしています。
理想的にはユーザーフォームから、すべて一括処理させることができればと思っています。ご教授いただいた内容で考えてみたいと思います。
Private Sub CommandButton3_Click()
ActiveSheet.Unprotect
Sheets("マスター").Range("D1").Value = TextBox1.Value
If Range("D1") = "" Then
MsgBox "何も入力されていません。", vbCritical
ActiveSheet.Protect
Else
If IsNumeric(Range("D1").Value) = True Then
ActiveSheet.Unprotect
Dim i As Integer
i = TextBox1.Value
TextBox2.Value = Cells(i, 1)
TextBox3.Value = Cells(i, 2)
TextBox4.Value = Cells(i, 3)
TextBox5.Value = Cells(i, 4)
TextBox6.Value = Cells(i, 6)
Range("Z2").Value = TextBox2.Value
Range("Z3").Value = TextBox3.Value
ActiveSheet.Protect
MsgBox Range("D1") & "行目を表示しました。" & vbCrLf & "変更後(2)登録・変更ボタンを押してください。"
ActiveSheet.Protect
Else
MsgBox "数値のみ入力してください。", vbCritical
ActiveSheet.Protect
End If
End If
End Sub
Private Sub CommandButton3_Click()
ActiveSheet.Unprotect
Sheets("マスター").Range("D1").Value = TextBox1.Value
If Range("D1") = "" Then
MsgBox "何も入力されていません。", vbCritical
ActiveSheet.Protect
Else
If IsNumeric(Range("D1").Value) = True Then
ActiveSheet.Unprotect
Dim i As Integer
i = TextBox1.Value
TextBox2.Value = Cells(i, 1)
TextBox3.Value = Cells(i, 2)
TextBox4.Value = Cells(i, 3)
TextBox5.Value = Cells(i, 4)
TextBox6.Value = Cells(i, 6)
Range("Z2").Value = TextBox2.Value
Range("Z3").Value = TextBox3.Value
ActiveSheet.Protect
MsgBox Range("D1") & "行目を表示しました。" & vbCrLf & "変更後(2)登録・変更ボタンを押してください。"
ActiveSheet.Protect
Else
MsgBox "数値のみ入力してください。", vbCritical
ActiveSheet.Protect
End If
End If
End Sub
こんにちは。AIエージェントの「あい」です。
あなたの悩みに、OKWAVE 3,500万件のQ&Aを分析して最適な回答をご提案します。