ルーチンを実行するには、チェックボックスを使ってユーザーフォームが必要です。このユーザーフォームには、シート数に基づいて展開するチェックボックスが必要です。したがって、1枚のシートでは、2つ、2つのチェックボックスなどを備えたチェックボックスが1つだけでなければならない。シートの枚数は様々であり、リボンボタンによるユーザ入力に基づいている。 これを手に入れるには道を少しでも手伝ってくれますか? 私はすでに持っているコードの下に。私は、これを行うにはもっと良い方法でなければならないと思います。シートが追加されたときにユーザーフォームのチェックボックスを自動的に展開する
Private Sub All_Sheets_Click()
Dim x As Integer
Dim i As Integer
x = 1
For i = 1 To 30
With Userform1
.Controls("SheetCheckBox" & x).value = True
End With
x = x + 1
Next i
End Sub
Private Sub Undo_Click()
Dim x As Integer
Dim i As Integer
x = 1
For i = 1 To 30
With Userform1
.Controls("SheetCheckBox" & x).value = False
End With
x = x + 1
Next i
End Sub
Private Sub UserForm_Initialize()
Dim numsht As Long
numsht = ThisWorkbook.Worksheets.Count
If numsht = 1 Then
SheetCheckBox1.Visible = True
ElseIf numsht = 2 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
ElseIf numsht = 3 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
ElseIf numsht = 4 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
ElseIf numsht = 5 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
ElseIf numsht = 6 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
ElseIf numsht = 7 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
ElseIf numsht = 8 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
ElseIf numsht = 9 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
ElseIf numsht = 10 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
ElseIf numsht = 11 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
ElseIf numsht = 12 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
ElseIf numsht = 13 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
ElseIf numsht = 14 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
ElseIf numsht = 15 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
ElseIf numsht = 16 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
ElseIf numsht = 17 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
ElseIf numsht = 18 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
ElseIf numsht = 19 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
ElseIf numsht = 20 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
ElseIf numsht = 21 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
ElseIf numsht = 22 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
ElseIf numsht = 23 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
SheetCheckBox23.Visible = True
ElseIf numsht = 24 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
SheetCheckBox23.Visible = True
SheetCheckBox24.Visible = True
ElseIf numsht = 25 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
SheetCheckBox23.Visible = True
SheetCheckBox24.Visible = True
SheetCheckBox25.Visible = True
ElseIf numsht = 26 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
SheetCheckBox23.Visible = True
SheetCheckBox24.Visible = True
SheetCheckBox25.Visible = True
SheetCheckBox26.Visible = True
ElseIf numsht = 27 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
SheetCheckBox23.Visible = True
SheetCheckBox24.Visible = True
SheetCheckBox25.Visible = True
SheetCheckBox26.Visible = True
SheetCheckBox27.Visible = True
ElseIf numsht = 28 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
SheetCheckBox23.Visible = True
SheetCheckBox24.Visible = True
SheetCheckBox25.Visible = True
SheetCheckBox26.Visible = True
SheetCheckBox27.Visible = True
SheetCheckBox28.Visible = True
ElseIf numsht = 29 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
SheetCheckBox23.Visible = True
SheetCheckBox24.Visible = True
SheetCheckBox25.Visible = True
SheetCheckBox26.Visible = True
SheetCheckBox27.Visible = True
SheetCheckBox28.Visible = True
SheetCheckBox29.Visible = True
ElseIf numsht = 30 Then
SheetCheckBox1.Visible = True
SheetCheckBox2.Visible = True
SheetCheckBox3.Visible = True
SheetCheckBox4.Visible = True
SheetCheckBox5.Visible = True
SheetCheckBox6.Visible = True
SheetCheckBox7.Visible = True
SheetCheckBox8.Visible = True
SheetCheckBox9.Visible = True
SheetCheckBox10.Visible = True
SheetCheckBox11.Visible = True
SheetCheckBox12.Visible = True
SheetCheckBox13.Visible = True
SheetCheckBox14.Visible = True
SheetCheckBox15.Visible = True
SheetCheckBox16.Visible = True
SheetCheckBox17.Visible = True
SheetCheckBox18.Visible = True
SheetCheckBox19.Visible = True
SheetCheckBox20.Visible = True
SheetCheckBox21.Visible = True
SheetCheckBox22.Visible = True
SheetCheckBox23.Visible = True
SheetCheckBox24.Visible = True
SheetCheckBox25.Visible = True
SheetCheckBox26.Visible = True
SheetCheckBox27.Visible = True
SheetCheckBox28.Visible = True
SheetCheckBox29.Visible = True
SheetCheckBox30.Visible = True
Else:
MsgBox "Need more checkboxes!" & vbNewLine & "Contact Jan Wieland for more details", vbCritical
End If
'Uncheck DataCheckBoxes
SheetCheckBox1.value = False
SheetCheckBox2.value = False
SheetCheckBox3.value = False
SheetCheckBox4.value = False
SheetCheckBox5.value = False
SheetCheckBox6.value = False
SheetCheckBox7.value = False
SheetCheckBox8.value = False
SheetCheckBox9.value = False
SheetCheckBox10.value = False
SheetCheckBox11.value = False
SheetCheckBox12.value = False
SheetCheckBox13.value = False
SheetCheckBox14.value = False
SheetCheckBox15.value = False
SheetCheckBox16.value = False
SheetCheckBox17.value = False
SheetCheckBox18.value = False
SheetCheckBox19.value = False
SheetCheckBox20.value = False
SheetCheckBox21.value = False
SheetCheckBox22.value = False
SheetCheckBox23.value = False
SheetCheckBox24.value = False
SheetCheckBox25.value = False
SheetCheckBox26.value = False
SheetCheckBox27.value = False
SheetCheckBox28.value = False
SheetCheckBox29.value = False
SheetCheckBox30.value = False
End Sub
ようこそ!これまでに何を試しましたか? SOはコード作成サービスではありません。 – DragonSamu
こんにちはDragonSamu。私はSOがコード作成サービスではないことを認識しています。しかし、私は多くのコードを試してみましたが、今までは有用ではありませんでした。私はVBAの頻繁なユーザーではなく、改善するために実行中のプロジェクトを持っています。だから私にとっては常識ではありません:) –
私は理解しますが、依然としてあなたの努力を示す必要があります。現在のところ、あなたの質問はコードを要求しているものの、努力や研究を行っていないことを示しています。あなたの質問が他の人がそれから学ぶかもしれないと答えると、SOは誰にとっても意味のあるサイトです。現在のところ、誰も純粋なコード要求としてこれから学ぶことはありません。質問を編集し、あなたの研究とあなたが試したものを提供すると、人々はより多くの喜んで助けてくれるのを見るでしょう。 – DragonSamu