| 
    
     |  | ▼LALA さん: 
 こんにちは
 
 当分、帰ってこられないかもしれないので、このコードも目にとまらないかもしれませんが?
 なんとなく想像で、イメージしていらっしゃることはこんなことなんだろうなというコード。
 
 最初が「基本形」、2番目が「ブラッシュアップ版」
 
 Private Sub CommandButton_Click()
 Dim tot As Long
 Dim myMSG As String
 Dim myFlg As Boolean
 
 If CheckBox1.Value = True Then
 tot = tot + Worksheets("Sheet1").Range("A1").Value
 myMSG = myMSG & CheckBox1.Caption & vbCrLf & vbCrLf
 myFlg = True
 End If
 If CheckBox2.Value = True Then
 tot = tot + Worksheets("Sheet1").Range("A2").Value
 myMSG = myMSG & CheckBox2.Caption & vbCrLf & vbCrLf
 myFlg = True
 End If
 If CheckBox3.Value = True Then
 tot = tot + Worksheets("Sheet1").Range("A3").Value
 myMSG = myMSG & CheckBox3.Caption & vbCrLf & vbCrLf
 myFlg = True
 End If
 If CheckBox4.Value = True Then
 tot = tot + Worksheets("Sheet1").Range("A4").Value
 myMSG = myMSG & CheckBox4.Caption & vbCrLf & vbCrLf
 myFlg = True
 End If
 If CheckBox5.Value = True Then
 tot = tot + Worksheets("Sheet1").Range("A5").Value
 myMSG = myMSG & CheckBox5.Caption & vbCrLf & vbCrLf
 myFlg = True
 End If
 If CheckBox6.Value = True Then
 tot = tot + Worksheets("Sheet1").Range("A6").Value
 myMSG = myMSG & CheckBox6.Caption & vbCrLf & vbCrLf
 myFlg = True
 End If
 If myFlg = True Then
 If MsgBox(Chr(10) & Chr(10) & myMSG & " にチェックが入っおり、合計は " & tot & " です。この選択でいいですか?", _
 vbYesNo + vbDefaultButton2 + vbQuestion, "重要") = vbYes Then
 Worksheets("Sheet1").Range("A9").Value = tot
 '作成中の他にやる処理をここに。
 'このあたりは、コードが多くなると見づらくなるのでサブプロシジャ化も検討してね。
 Unload Me
 Else
 CheckBox1.Value = False
 CheckBox2.Value = False
 CheckBox3.Value = False
 CheckBox4.Value = False
 CheckBox5.Value = False
 CheckBox6.Value = False
 End If
 Else
 MsgBox "いずれにもチェックが入っていません"
 End If
 End Sub
 
 
 Private Sub CommandButton_Click()
 Dim tot As Long
 Dim myMSG As String
 Dim myFlg As Boolean
 Dim i As Long
 
 With Worksheets("SHeet1")
 
 For i = 1 To 6 'CheckBox1〜CheckBox6
 
 If Me.Controls("CheckBox" & i).Value Then
 tot = tot + .Range("A" & i).Value
 myMSG = myMSG & Me.Controls("CheckBox" & i).Caption & vbCrLf & vbCrLf
 myFlg = True
 End If
 
 Next
 
 If myFlg = True Then
 If MsgBox(Chr(10) & Chr(10) & myMSG & " にチェックが入っおり、合計は " & tot & " です。この選択でいいですか?", _
 vbYesNo + vbDefaultButton2 + vbQuestion, "重要") = vbYes Then
 .Range("A9").Value = tot
 '作成中の他にやる処理をここに。
 'このあたりは、コードが多くなると見づらくなるのでサブプロシジャ化も検討してね。
 Unload Me
 Else
 For i = 1 To 6
 Me.Controls("CheckBox" & i).Value = False
 Next
 End If
 Else
 MsgBox "いずれにもチェックが入っていません"
 End If
 
 End With
 
 End Sub
 
 |  |