

Userformで転記しているのですが
チェックボックス入れると今までと違う指定したセルに、チェックない時は今まで通り転記するようなことできますか?
現状このようにしていますが
If Cells(iCheck, 4).Value = Me.TextBox3.Text Then
If Cells(iCheck, 17).Value = "" Then
Cells(iCheck, 17).Value = CDate(TextBox1.Value)
Cells(iCheck, 18).Value = Me.ComboBox1
Cells(iCheck, 19).Value = Me.ComboBox2
Cells(iCheck, 20).Value = Me.TextBox2
Me.TextBox3.Text = ""
Me.TextBox3.SetFocus
チェックボックスを有効にしたら24~27に転記し17~23のセルをクリアしたいです
Cells(iCheck, 24).Value = CDate(TextBox1.Value)
Cells(iCheck, 25).Value = Me.ComboBox1
Cells(iCheck, 26).Value = Me.ComboBox2
Cells(iCheck, 27).Value = Me.TextBox2
Cells(iCheck, 17).Value = ””
Cells(iCheck, 18).Value = ””
Cells(iCheck, 19).Value = ””
Cells(iCheck, 20).Value = ””
Cells(iCheck, 21).Value = ””
Cells(iCheck, 22).Value = ””
Cells(iCheck, 23).Value = ””
A 回答 (5件)
- 最新から表示
- 回答順に表示
No.5
- 回答日時:
>頂いたまんま実行したらQ1~W8の記入のあるセルまでがクリアされX2列~AA9までが転記されました・・・
>省略の部分に回答者追加分を入れて実行ですか?
「頂いたまんま実行したら」とは、
No4の
https://ideone.com/gJsLRV
のことでしょうか。
49~60行が私が追加した部分です。
これを追加すると
確かに、Q1~W8の記入のあるセルまでがクリアされます。
下記が、あなたが、希望された処理なので、それを追加しただけなのですが、まずかったでしょうか?
チェックボックスを有効にしたら24~27に転記し17~23のセルをクリアしたいです
Cells(iCheck, 24).Value = CDate(TextBox1.Value)
Cells(iCheck, 25).Value = Me.ComboBox1
Cells(iCheck, 26).Value = Me.ComboBox2
Cells(iCheck, 27).Value = Me.TextBox2
Cells(iCheck, 17).Value = ””
Cells(iCheck, 18).Value = ””
Cells(iCheck, 19).Value = ””
Cells(iCheck, 20).Value = ””
Cells(iCheck, 21).Value = ””
Cells(iCheck, 22).Value = ””
Cells(iCheck, 23).Value = ””
No.4
- 回答日時:
>教えていただいたコードの前後はこのようなのですが動きませんでした
提示されたソースに追記しました。下記URLを参照ください。
https://ideone.com/gJsLRV
'回答者追加分のところです。
これでだめですか?
(こちらでは、テスト環境がつくれなかったので動作確認はしていません)
No.3
- 回答日時:
>全部に対してIf CheckBox1.Value Then必要ですよね?
「チェックボックスを有効にしたら24~27に転記し17~23のセルをクリアしたいです」ということなので、
No2のようにすれば良いです。
CheckBox1.Value の判定は1か所のみで十分です。
No.2
- 回答日時:
if CheckBox1.Value = False then
'今までの処理
If Cells(iCheck, 4).Value = Me.TextBox3.Text Then
If Cells(iCheck, 17).Value = "" Then
Cells(iCheck, 17).Value = CDate(TextBox1.Value)
Cells(iCheck, 18).Value = Me.ComboBox1
Cells(iCheck, 19).Value = Me.ComboBox2
Cells(iCheck, 20).Value = Me.TextBox2
Me.TextBox3.Text = ""
Me.TextBox3.SetFocus
else
'チェックボックスを有効にしたときの処理
Cells(iCheck, 24).Value = CDate(TextBox1.Value)
Cells(iCheck, 25).Value = Me.ComboBox1
Cells(iCheck, 26).Value = Me.ComboBox2
Cells(iCheck, 27).Value = Me.TextBox2
Cells(iCheck, 17).Value = ””
Cells(iCheck, 18).Value = ””
Cells(iCheck, 19).Value = ””
Cells(iCheck, 20).Value = ””
Cells(iCheck, 21).Value = ””
Cells(iCheck, 22).Value = ””
Cells(iCheck, 23).Value = ””
end if
のようになります。
Private Sub CommandButton1_Click()
Dim i As Integer
Dim iCheck As Integer
Dim RowNum As Long
'入力チェック
If Me.TextBox1 = "" Then
MsgBox "日付が入力されてません"
Exit Sub
End If
If Me.TextBox2 = "" Then
MsgBox "担当が入力されてません"
Exit Sub
End If
If Me.ComboBox1 = "" Then
MsgBox "出荷先が入力されてません"
Exit Sub
End If
If Me.TextBox3 = "" Then
MsgBox "シリアル№が入力されてません"
Exit Sub
End If
If Me.ComboBox2 = "" Then
MsgBox "販売形式が入力されてません"
Exit Sub
End If
For i = 1 To 20000
If Cells(i, 1).Value = "" Then Exit For
Next
'重複チェック
iCheck = i
For iCheck = 1 To i
If CheckBox1.Value = False Then
'今までの処理
If Cells(iCheck, 4).Value = Me.TextBox3.Text Then
If Cells(iCheck, 17).Value = "" Then
~~~~省略~~~~
Cells(iCheck, 23).Value = ""
End If
Exit Sub
Else
MsgBox "既に出荷されてます"
Cells(iCheck, 4).Select
Me.TextBox3.SetFocus
Exit Sub
End If
Else
End If
Next
End Sub
教えていただいたコードの前後はこのようなのですが動きませんでした
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
Excel UserForm の表示位置
-
VBAマクロ実行時エラーの修正に...
-
【ExcelVBA】値を変更しながら...
-
Excelで空白セル直前のセルデー...
-
エクセルVBA 配列からセルに「...
-
昨日、質問した件『VBA にて、...
-
【Excel VBA】マクロで書き込ん...
-
VBA にて、条件付き書式で背景...
-
DataGridViewのフォーカス遷移...
-
特定の色のついたセルを削除
-
[VBA]変数を利用して時間を検索...
-
QRコード作成マクロについて
-
エクセル VBA ボタンをクリック...
-
【VBA】【ユーザーフォーム_Lis...
-
セルの半透明着色処理
-
マクロ初心者です。 マクロで範...
-
excelで結合セルの場合にエラー...
-
エクセルのカーソルを非表示に...
-
マクロ
-
エクセルVBA ダブルクリックし...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
Excel UserForm の表示位置
-
VBAマクロ実行時エラーの修正に...
-
特定の色のついたセルを削除
-
Excelで空白セル直前のセルデー...
-
エクセルVBA 配列からセルに「...
-
【VBA】【ユーザーフォーム_Lis...
-
【VBA】写真の貼り付けコードが...
-
データグリッドビューの結合セ...
-
複数指定セルの可視セルのみを...
-
エクセル、マクロで番号を読込...
-
CellEnterイベント仕様について
-
C# DataGridViewで複数選択した...
-
【ExcelVBA】値を変更しながら...
-
EXCEL VBA 文中の書式ごと複写...
-
マクロ初心者です。 マクロで範...
-
【Excel VBA】一番右端セルまで...
-
【Excel VBA】マクロで書き込ん...
-
VBA:日付を配列に入れ別セルに...
-
DataGridViewでグリッド内に線...
-
DataGridViewのフォーカス遷移...
おすすめ情報
if CheckBox1.Value then
Cells(iCheck, 17).Value = CDate(TextBox1.Value)
else
Cells(iCheck, 24).Value = CDate(TextBox1.Value)
end if
Cells(iCheck, 18).Value = Me.ComboBox1
else
Cells(iCheck, 25).Value = Me.ComboBox1
end if
Cells(iCheck, 19).Value = Me.ComboBox2
else
Cells(iCheck, 26).Value = Me.ComboBox2
end if
Cells(iCheck, 20).Value = Me.TextBox2
else
Cells(iCheck, 27).Value = Me.TextBox2
end if
全部に対してIf CheckBox1.Value Then必要ですよね?