『ユーザーフォームで入力した後のデータについて』(エフワン)
ユーザーフォームで入力表を作って、データを全て入力し、データ
をシートに飛ばした後、ユーザーフォームの各入力項目について
ある項目はデータをクリアし、ある項目はデータを残す事はできますか。
その場合、コードはどのようなしたらよろしいでしょうか。
アドバイスをお願いします。
< 使用 Excel:Microsoft365、使用 OS:Windows11 >
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
' TextBox3 はそのまま何もしない(値を残す)
とすれば、
Excel VBAのユーザーフォームで、
「一部の入力項目はクリアして、一部はそのまま残す」ようにできますが?
(稚拙) 2026/04/29(水) 06:00:49
こんな感じでいいんじゃない?
For i = 1 To 2
Me.Controls("TextBox" & i).Value = ""
Next
(はんぺん) 2026/04/29(水) 06:33:12
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim lastRow As Long
Set ws = ThisWorkbook.Sheets("Sheet1")
'A列の最終行を取得
lastRow = ws.Cells(ws.Rows.count, "A").End(xlUp).Row
If lastRow < 2 Then lastRow = 1
ws.Cells(lastRow + 1, "A").Value = TextBox1.Value
TextBox1.Value = ""
TextBox1.SetFocus
End Sub
Private Sub CommandButton2_Click()
Dim ws As Worksheet
Dim findRng As Range
Set ws = ThisWorkbook.Sheets("Sheet5")
Set findRng = ws.Columns("A").Find(What:=TextBox1.Value,LookAt:=xlWhole)
If Not findRng Is Nothing Then
findRng.EntireRow.Delete
MsgBox "削除しました"
TextBox1.Value = ""
TextBox1.SetFocus
Else
MsgBox "該当データが見つかりません"
End If
End Sub
(マクロ苦手) 2026/04/29(水) 11:31:27
【userform】
Sheets("マクロ").Select
Range("b3").Select
ActiveCell.Value = ComboBox1.Value
Range("c3").Select
ActiveCell.Value = ComboBox2.Value
Range("d3").Select
ActiveCell.Value = ComboBox3.Value
Range("e3").Select
ActiveCell.Value = ComboBox4.Value
Range("f3").Select
ActiveCell.Value = ComboBox5.Value
Range("g3").Select
ActiveCell.Value = TextBox1.Value
Range("H3").Select
ActiveCell.Value = ComboBox8.Value
Range("I3").Select
ActiveCell.Value = TextBox2.Value
Range("j3").Select
ActiveCell.Value = TextBox3.Value
Range("K3").Select
ActiveCell.Value = TextBox4.Value
Sheets("マクロ").Select
ActiveSheet.Calculate
Range("b3:k3").Select
Selection.Copy
Range("a1").Select
Sheets("手持ち業務一覧").Select
If Range("B6") = "" Then
Range("B6").Select
Else
Range("B6").CurrentRegion.End(xlDown).Offset(1, 0).Select
End If
ActiveCell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("手持ち業務一覧").Select
Range("B6:C1000").Select
Selection.NumberFormatLocal = "000"
Range("B6").Select
TextBox1.Value = Empty
TextBox2.Value = Empty
TextBox3.Value = Empty
TextBox4.Value = Empty
ComboBox1.Value = Empty
ComboBox2.Value = Empty
ComboBox3.Value = ""
ComboBox4.Value = ""
ComboBox5.Value = Empty
ComboBox8.Value = Empty
Sheets("マクロ").Select
End Sub
(エフワン) 2026/04/29(水) 17:27:44
という場合、combobx3、4はどのような構文になるのでしょうか。
(エフワン) 2026/04/29(水) 20:29:12
>emptyのままだと消えますし、""しても消えてしまいます。
それって、当たり前じゃないですか?(上書きしているのですから)
前の値をそのままにして置きたいなら、何も書かないようにしてください。
(半平太) 2026/04/29(水) 21:02:03
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.