アプリ版:「スタンプのみでお礼する」機能のリリースについて

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 = ””

質問者からの補足コメント

  • 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

    No.1の回答に寄せられた補足コメントです。 補足日時:2023/05/31 18:37
  • うーん・・・

    全部に対してIf CheckBox1.Value Then必要ですよね?

      補足日時:2023/05/31 18:45

A 回答 (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 = ””
    • good
    • 0

>教えていただいたコードの前後はこのようなのですが動きませんでした



提示されたソースに追記しました。下記URLを参照ください。
https://ideone.com/gJsLRV
'回答者追加分のところです。

これでだめですか?
(こちらでは、テスト環境がつくれなかったので動作確認はしていません)
    • good
    • 0

>全部に対してIf CheckBox1.Value Then必要ですよね?



「チェックボックスを有効にしたら24~27に転記し17~23のセルをクリアしたいです」ということなので、
No2のようにすれば良いです。
CheckBox1.Value の判定は1か所のみで十分です。
    • good
    • 0

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

のようになります。
    • good
    • 0
この回答へのお礼

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
教えていただいたコードの前後はこのようなのですが動きませんでした

お礼日時:2023/06/01 13:26

if チェックボックスが無効 then


今までの処理
else
チェックボックスが有効の時の処理
end if

のようにすれば良いです。
この回答への補足あり
    • good
    • 0
この回答へのお礼

頂いたまんま実行したらQ1~W8の記入のあるセルまでがクリアされX2列~AA9までが転記されました・・・
省略の部分に回答者追加分を入れて実行ですか?

お礼日時:2023/06/01 14:27

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!