엑셀VBA 유용한 명령어 모음
VBA는 VB랑 미묘하게 달라서 안되는 것들도 있고 명령어들도 다르다.
일단 시트를 기반으로 한 명령어들이 다른데 엑셀이란 강력한 군대가 지원해주니
오히려 원조VB보다 강력하단 느낌이다.
좀 느리긴 하지만(그리고 번거로운 과정이 있긴 하지만) 오토마우스, 오토키보드도 만들 수 있다.
덕분에 회사에서 아주 잘 쓰고 있고.
가장 불편한 점이라면 폼 내부에서 컨트롤을 배치할 때 배열 적용이 안된단 사실이다.
도저히 이해할 수 없다.
1. 엑셀 제목표시줄에 글자 표시
Application.Caption = “”
파일이름이 들어가는 제목표시줄 부분에 글자가 표시된다.
2. 특정시트로 이동
SHT = “시트이름”
Sheets(SHT).Select
3. 특정셀 선택
Range(“A1”).Select
4. 특정시트의 값 가져오기
SHT = “시트이름”
Sheets(SHT).Range(“A1”).Value
5. A열인지 아닌지 확인
If ActiveCell.Offset(0, 0).Column <> 1 Then
6. 현재 셀 기억
줄 기억 => a = ActiveCell.Offset(0, 0).Row
칸 기억 => a = ActiveCell.Offset(0, 0).Column
주소 기억 => b = ActiveCell.Offset(0, 0).Address
7. 셀 드래그
a = ActiveCell.Offset(?, ?).Address
b = ActiveCell.Offset(?, ?).Address
Range(a & “:” & b).Select
8. 글꼴 조정
Range(“A1:D1”).Select
Selection.Font.Bold = False
Selection.Font.Name = “돋움”
Selection.Font.Size = 11
9. 배경 없음
Range(“A1:D1”).Select
Selection.Interior.Pattern = xlNone
Selection.Interior.TintAndShade = 0
Selection.Interior.PatternTintAndShade = 0
10. 배경 노란색
Range(“A1:D1”).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
11. 한 줄 아래로
ActiveCell.Offset(1, 0).Select
(한 줄 오른쪽은 0, 1)
12. 특정글자 변경(Replace)
b = Replace(a, “x”, “*”) ‘x를 *로 바꿈
13. 검색
aaaa = “문자열”
On Error Resume Next ‘오류가 나도 다음으로
Cells.Find(What:=aaaa, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext _
, MatchCase:=False, MatchByte:=False, SearchFormat:=False).Activate
If Err <> 0 Then ‘MsgBox “검색된 셀이 없습니다”, 64, “검색 실패”
Err.Clear
End If
On Error GoTo 0