[엑셀 #004] Macro 이용하여 두 셀 바꾸기 (Shuffling)
2019. 9. 4. 12:01ㆍ짭지식_Things to take notes/워드&엑셀_Word&Excel
두 개의 셀을 클릭만으로 바꾸고 싶을 때(Shuffling) 사용하는 방법이다. 엑셀에 아래와 같은 셀들이 있다고 하자.
1. 원하는 모양을 삽입한다. (insert --> shape)
2. 오른쪽 버튼으로 Macro를 적용한다. (Assign Macro)
3. 'New' 버튼 클릭.
4. 편집창(Code) 부분에 아래 text를 붙여 넣는다.
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
38
39
40
41
42
43
|
Sub change_cell()
Dim intAreas As Integer
Dim rngLeft As Range
Dim rngRight As Range
Dim varTemp
With Selection
intAreas = .Areas.Count
If intAreas <> 2 Then
MsgBox "select 2 cells", 64, "error"
Exit Sub
End If
Set rngLeft = .Areas(1)
Set rngRight = .Areas(2)
If rngLeft.Rows.Count <> rngRight.Rows.Count Or _
rngLeft.Columns.Count <> rngRight.Columns.Count Then
MsgBox "select same size cells", 64, "error"
Exit Sub
End If
End With
varTemp = rngLeft
rngLeft = rngRight.Value
rngRight = varTemp
Set rngLeft = Nothing
Set rngRight = Nothing
End Sub
|
cs |
5. 두 개의 셀을 'Ctrl'로 이용하여 클릭한 후 위에서 만든 모양을 클릭하면 두 셀이 바뀐다.
(뒤로 가기('Ctrl+z')는 안 되니 주의!)
'짭지식_Things to take notes > 워드&엑셀_Word&Excel' 카테고리의 다른 글
[엑셀 #006] 문자 또는 숫자 자릿수 맞추기 (REPT or TEXT 함수) (0) | 2019.09.05 |
---|---|
[엑셀 #005] 특정문자가 들어간 셀 세기 (countif) (0) | 2019.09.04 |
[엑셀 #003] index, match 함수로 다중 조건(2개 이상)의 값 찾기 (0) | 2019.09.03 |
[엑셀 #002] sumproduct를 이용해 다른 Table 동일한 좌표의 데이터 찾아오기 (1) | 2019.09.03 |
[엑셀 #001] offset 함수로 1/4을 전체로 확장하기 (0) | 2019.09.03 |