添付にあるようにセルをひとつひとつ入力し直すのではなくシフト表の変更を簡単にVBAでできますか?

1件の回答

回答を書く

1019927

2026-05-31 19:45

+ フォロー

素人が組む単純なコードですが、ユーザーフォームでの入力作業を許容できるのであれば参考まで。

添付図の赤枠の氏名の一覧、勤務の一覧に、タブ「数式」⇒「名前の管理」でそれぞれに名前を設定します。

ここでは、それぞれの名前を「氏名」、「勤務」としています。

ComboBox1のプロパティ「RowSource」に「氏名」、同様にComboBox2のプロパティ「RowSource」に「勤務」と設定します。

勤務が有給であれば、赤に塗りつぶし休日と表示。

休日であればグレーに塗りつぶし。

その他の勤務であれば、A列の氏名の背景色と同じ背景色とします。



Sub ボタン1_Click()

With UserForm1

.ComboBox1.Value = \u0026quot;\u0026quot;

.TextBox1.Value = \u0026quot;\u0026quot;

.ComboBox2.Value = \u0026quot;\u0026quot;

.Show

End With

End Sub



Private Sub CommandButton1_Click()

Dim c As Long

If TextBox1.Value \u0026lt;\u0026gt; \u0026quot;\u0026quot; Then

For c = 2 To Cells(3, Columns.Count).End(xlToLeft).Column

If DateValue(TextBox1.Value) = Cells(3, c).Value Then

If ComboBox2.Value = \u0026quot;有給\u0026quot; Then

Cells(4 + ComboBox1.ListIndex, c).Value = \u0026quot;休日\u0026quot;

Cells(4 + ComboBox1.ListIndex, c).Interior.ColorIndex = 3

ElseIf ComboBox2.Value = \u0026quot;休日\u0026quot; Then

Cells(4 + ComboBox1.ListIndex, c).Value = \u0026quot;休日\u0026quot;

Cells(4 + ComboBox1.ListIndex, c).Interior.ColorIndex = 48

Else

Cells(4 + ComboBox1.ListIndex, c).Value = ComboBox2.Value

Cells(4 + ComboBox1.ListIndex, c).Interior.ColorIndex _

= Cells(4 + ComboBox1.ListIndex, \u0026quot;A\u0026quot;).Interior.ColorIndex

End If

Exit For

End If

Next c

End If

'リセット

ComboBox1.Value = \u0026quot;\u0026quot;

ComboBox2.Value = \u0026quot;\u0026quot;

TextBox1.Value = \u0026quot;\u0026quot;

ComboBox1.SetFocus

End Sub



Private Sub CommandButton2_Click()

UserForm1.Hide

End Sub

うったえる有益だ(0シェアするブックマークする

関連質問

Copyright © 2026 AQ188.com All Rights Reserved.

博識 著作権所有