回答編集履歴
2
追記
test
CHANGED
@@ -17,3 +17,113 @@
|
|
17
17
|
Next
|
18
18
|
|
19
19
|
```
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
<追記>
|
24
|
+
|
25
|
+
こういうことですか?
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```VBA
|
30
|
+
|
31
|
+
Private Sub CommandButton1_Click()
|
32
|
+
|
33
|
+
Dim trgtSh As Worksheet
|
34
|
+
|
35
|
+
Dim trgtSh2 As Worksheet
|
36
|
+
|
37
|
+
Set trgtSh = Worksheets("入力")
|
38
|
+
|
39
|
+
Set trgtSh2 = Worksheets("グラフ")
|
40
|
+
|
41
|
+
Dim dataRng As Range
|
42
|
+
|
43
|
+
Set dataRng = trgtSh.Range("A1:D4")
|
44
|
+
|
45
|
+
Dim pasteRng As Range
|
46
|
+
|
47
|
+
Set pasteRng = trgtSh2.Range("G2")
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
'グラフ作成
|
52
|
+
|
53
|
+
With trgtSh2.Shapes.AddChart.Chart
|
54
|
+
|
55
|
+
.ChartType = xlColumnClustered
|
56
|
+
|
57
|
+
.SetSourceData dataRng
|
58
|
+
|
59
|
+
.HasTitle = True
|
60
|
+
|
61
|
+
.ChartTitle.Text = "売上"
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
.Parent.Top = pasteRng.Top
|
66
|
+
|
67
|
+
.Parent.Left = pasteRng.Left
|
68
|
+
|
69
|
+
End With
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
'ボタン追加(位置の準備)
|
74
|
+
|
75
|
+
Dim wLeft, wTop
|
76
|
+
|
77
|
+
With trgtSh2.Shapes(1)
|
78
|
+
|
79
|
+
wLeft = .Left + .Width + 10
|
80
|
+
|
81
|
+
wTop = .Top + 10
|
82
|
+
|
83
|
+
End With
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
'1つめのボタン
|
88
|
+
|
89
|
+
Dim bt1 As Button
|
90
|
+
|
91
|
+
Set bt1 = trgtSh2.Buttons.Add(wLeft, wTop, 100, 100)
|
92
|
+
|
93
|
+
With bt1
|
94
|
+
|
95
|
+
.Caption = "ボタン名1"
|
96
|
+
|
97
|
+
.OnAction = "Sub名1"
|
98
|
+
|
99
|
+
.AutoSize = True
|
100
|
+
|
101
|
+
End With
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
'2つめのボタン
|
106
|
+
|
107
|
+
Dim bt2 As Button
|
108
|
+
|
109
|
+
wTop = wTop + bt1.Height + 10
|
110
|
+
|
111
|
+
Set bt2 = trgtSh2.Buttons.Add(wLeft, wTop, 100, 100)
|
112
|
+
|
113
|
+
With bt2
|
114
|
+
|
115
|
+
.Caption = "ボタン名2"
|
116
|
+
|
117
|
+
.OnAction = "Sub名2"
|
118
|
+
|
119
|
+
.AutoSize = True
|
120
|
+
|
121
|
+
End With
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
End Sub
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```
|
1
修正
test
CHANGED
@@ -6,10 +6,14 @@
|
|
6
6
|
|
7
7
|
For Each bt In trgtSh.Buttons
|
8
8
|
|
9
|
-
trgtSh2.Buttons.Add(bt.Left, bt.Top, bt.Width, bt.Height)
|
9
|
+
With trgtSh2.Buttons.Add(bt.Left, bt.Top, bt.Width, bt.Height)
|
10
|
+
|
11
|
+
.Caption = bt.Caption
|
12
|
+
|
13
|
+
.OnAction = bt.OnAction
|
14
|
+
|
15
|
+
End With
|
10
16
|
|
11
17
|
Next
|
12
18
|
|
13
|
-
|
14
|
-
|
15
19
|
```
|