質問するログイン新規登録

質問編集履歴

1

userformのコード追記

2017/09/18 04:54

投稿

webillion
webillion

スコア33

title CHANGED
File without changes
body CHANGED
@@ -10,4 +10,106 @@
10
10
 
11
11
  以前にもエクセルを立ち上げたときに、ユーザーフォームが表示されるシステムを作りましたが、その時は今回のようなエラーメッセージは掃かれませんでした。
12
12
 
13
- 分かる方、ご教示願います。
13
+ 分かる方、ご教示願います。
14
+
15
+ UserFormのコードを追記いたします。
16
+
17
+ ```
18
+
19
+ Private Sub ComboBox1_Change()
20
+
21
+ End Sub
22
+
23
+ Private Sub CommandButton1_Click()
24
+ Dim i
25
+ For i = 10 To 60 Step 10
26
+ ComboBox1.AddItem i & "分"
27
+ Next
28
+ End Sub
29
+
30
+ Private Sub CommandButton2_Click()
31
+ Cells.Select
32
+ Selection.ColumnWidth = 2
33
+
34
+ If Cells(1, 1) = "" Then
35
+ Worksheets("Task").Cells(1, 1).Value = TextBox1.Value
36
+ Columns("A:E").AutoFit
37
+ If ComboBox1.Text = "10分" Then
38
+ Cells(1, 2).Interior.ColorIndex = 3
39
+ Cells(1, 2).Value = "□"
40
+ ElseIf ComboBox1.Text = "20分" Then
41
+ Range(Cells(1, 2), Cells(1, 3)).Interior.ColorIndex = 3
42
+ Range(Cells(1, 2), Cells(1, 3)).Value = "□"
43
+ ElseIf ComboBox1.Text = "30分" Then
44
+ Range(Cells(1, 2), Cells(1, 4)).Interior.ColorIndex = 3
45
+ Range(Cells(1, 2), Cells(1, 4)).Value = "□"
46
+ ElseIf ComboBox1.Text = "40分" Then
47
+ Range(Cells(1, 2), Cells(1, 5)).Interior.ColorIndex = 3
48
+ Range(Cells(1, 2), Cells(1, 5)).Value = "□"
49
+ ElseIf ComboBox1.Text = "50分" Then
50
+ Range(Cells(1, 2), Cells(1, 6)).Interior.ColorIndex = 3
51
+ Range(Cells(1, 2), Cells(1, 6)).Value = "□"
52
+ ElseIf ComboBox1.Text = "60分" Then
53
+ Range(Cells(1, 2), Cells(1, 7)).Interior.ColorIndex = 3
54
+ Range(Cells(1, 2), Cells(1, 7)).Value = "□"
55
+ End If
56
+ Else
57
+ 'MsgBox Maxcol
58
+
59
+
60
+ n = Cells(Rows.Count, 1).End(xlUp).Row + 1
61
+ 'MsgBox n
62
+ 'With Range("A" & n - 1).SpecialCells(xlLastCell)
63
+ With Cells(n - 1, Columns.Count).End(xlToLeft).Column
64
+ 'maxrow = .Row
65
+ l = Cells(n - 1, Columns.Count).End(xlToLeft).Column + 1
66
+ End With
67
+ 'MsgBox l
68
+
69
+ '最終行を求めてしまっている↓
70
+ ''m = Range("A" & n - 1).End(xlToRight).Column + 1
71
+ 'm = Range("A" & Columns.Count).End(xlToLeft).Column + 1
72
+ 'm = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 1)
73
+ ''MsgBox m
74
+ Worksheets("Task").Cells(n, 1).Value = TextBox1.Value
75
+ Columns("A:E").AutoFit
76
+ If ComboBox1.Text = "10分" Then
77
+ Cells(n, l).Interior.ColorIndex = 3
78
+ 'Range(n, m).Value = "□"
79
+ Cells(n, l).Value = "□"
80
+ ElseIf ComboBox1.Text = "20分" Then
81
+ Range(Cells(n, l), Cells(n, l + 1)).Interior.ColorIndex = 3
82
+ Range(Cells(n, l), Cells(n, l + 1)).Value = "□"
83
+ ElseIf ComboBox1.Text = "30分" Then
84
+ Range(Cells(n, l), Cells(n, l + 2)).Interior.ColorIndex = 3
85
+ Range(Cells(n, l), Cells(n, l + 2)).Value = "□"
86
+ ElseIf ComboBox1.Text = "40分" Then
87
+ Range(Cells(n, l), Cells(n, l + 3)).Interior.ColorIndex = 3
88
+ Range(Cells(n, l), Cells(n, l + 3)).Value = "□"
89
+ ElseIf ComboBox1.Text = "50分" Then
90
+ Range(Cells(n, l), Cells(n, l + 4)).Interior.ColorIndex = 3
91
+ Range(Cells(n, l), Cells(n, l + 4)).Value = "□"
92
+ ElseIf ComboBox1.Text = "60分" Then
93
+ Range(Cells(n, l), Cells(n, l + 5)).Interior.ColorIndex = 3
94
+ Range(Cells(n, l), Cells(n, l + 5)).Value = "□"
95
+ End If
96
+ End If
97
+ End Sub
98
+
99
+ Private Sub Label2_Click()
100
+
101
+ End Sub
102
+
103
+ Private Sub TextBox1_Change()
104
+
105
+ End Sub
106
+
107
+ Private Sub UserForm_Click()
108
+
109
+ End Sub
110
+
111
+ Private Sub UserForm_Initialize()
112
+ UserForm1.Show
113
+ End Sub
114
+
115
+ ```