버튼을 누를 때 마다 표시되는 문구가 달라지는 매크로
버튼 하나로 단계적 절차를 표현할 때 활용가능
Sub Calculate()
Application.ScreenUpdating = False
With ActiveSheet.Buttons(Application.Caller)
If .Caption = "Sum" Then
Cells(12, 1).Value = "=R[-2]C+R[-1]C"
Cells(12, 2).Value = "=R[-2]C+R[-1]C"
Cells(12, 3).Value = "=R[-2]C+R[-1]C"
Cells(9, 1).Value = .Caption
.Caption = "subtract"
ElseIf .Caption = "subtract" Then
Cells(12, 1).Value = "=R[-2]C-R[-1]C"
Cells(12, 2).Value = "=R[-2]C-R[-1]C"
Cells(12, 3).Value = "=R[-2]C-R[-1]C"
Cells(9, 1).Value = .Caption
.Caption = "Multiply"
ElseIf .Caption = "Multiply" Then
Cells(12, 1).Value = "=R[-2]C*R[-1]C"
Cells(12, 2).Value = "=R[-2]C*R[-1]C"
Cells(12, 3).Value = "=R[-2]C*R[-1]C"
Cells(9, 1).Value = .Caption
.Caption = "Divide"
ElseIf .Caption = "Divide" Then
Cells(12, 1).Value = "=R[-2]C/R[-1]C"
Cells(12, 2).Value = "=R[-2]C/R[-1]C"
Cells(12, 3).Value = "=R[-2]C/R[-1]C"
Cells(9, 1).Value = .Caption
.Caption = "Sum"
End If
End With
Application.ScreenUpdating = True
End Sub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
Sub Calculate()
Application.ScreenUpdating = False
With ActiveSheet.Buttons(Application.Caller)
If .Caption = "Sum" Then
Cells(12, 1).Value = "=R[-2]C+R[-1]C"
Cells(12, 2).Value = "=R[-2]C+R[-1]C"
Cells(12, 3).Value = "=R[-2]C+R[-1]C"
Cells(9, 1).Value = .Caption
.Caption = "subtract"
ElseIf .Caption = "subtract" Then
Cells(12, 1).Value = "=R[-2]C-R[-1]C"
Cells(12, 2).Value = "=R[-2]C-R[-1]C"
Cells(12, 3).Value = "=R[-2]C-R[-1]C"
Cells(9, 1).Value = .Caption
.Caption = "Multiply"
ElseIf .Caption = "Multiply" Then
Cells(12, 1).Value = "=R[-2]C*R[-1]C"
Cells(12, 2).Value = "=R[-2]C*R[-1]C"
Cells(12, 3).Value = "=R[-2]C*R[-1]C"
Cells(9, 1).Value = .Caption
.Caption = "Divide"
ElseIf .Caption = "Divide" Then
Cells(12, 1).Value = "=R[-2]C/R[-1]C"
Cells(12, 2).Value = "=R[-2]C/R[-1]C"
Cells(12, 3).Value = "=R[-2]C/R[-1]C"
Cells(9, 1).Value = .Caption
.Caption = "Sum"
End If
End With
Application.ScreenUpdating = True
End Sub
|
cs |
_
반응형