1. ๋ณ์ ์ค์
- Dim : Dimension์ ์ฝ์๋ก, ๋ณ์๋ฅผ ์ ์ธํ๋ ๋ช
๋ น์ด
- Dim ๋ค์ ์ฌ์ฉ์๊ฐ ์ง์ ํ ๋ณ์๋ช
์ ์
๋ ฅ
- AS ๋ค์ ํด๋น ๋ณ์์ ์๋ฃํ์ ์ง์ (์
๋ ฅํ์ง ์์๋ ๋ฌด๋ฐฉ)
Dim fileName As String
Dim fileSize As Integer
2. ์กฐ๊ฑด๋ฌธ๊ณผ ๋ฐ๋ณต๋ฌธ
2-1. If ๋ฌธ
If fileSize > 0 Then
Exit Sub
ElseIf fileSize = 0 Then
fileName = Cells(2, "A").Value
Else
fileName = Cells(3, "A").Value
End If
2-2. Case ๋ฌธ
Select Case Target.Column
: Target.Column ์ฆ, ์ด์ ๋ํ Case ๋ฌธ์
Case 7
: ์ผ๊ณฑ ๋ฒ์งธ ์ด์ธ G์ด์ ๋ปํจ
Target.Row
: ์ ํํ ์
์ ํ ๋ฒํธ๋ฅผ ๋ฆฌํด
Select Case Target.Column
Case 7
fileSize = 0
Case 10
Cells(Target.Row, "A").Value
Case Else
Exit Sub
End Select
2-3. For ๋ฌธ
For i = [์์๊ฐ] To [์ข
๋ฃ๊ฐ]
(์๋ต)
Next i
3. ์
์ ์ด
3-1. ํน์ ์
์ ํฌ์ปค์ค ์ฃผ๊ธฐ
If Target.Column = 2 And Target.Row = 7 Then
: ์ ํํ ํ๊ฒ์ด 2์ด(B์ด) 7ํ์ด๋ผ๋ฉด
Target.Value
: ์ ํํ ๋์ ์
์ ๊ฐ์ ๊ฐ์ ธ์ด
Range("B4")
๋๋ Cells(4, "B")
: B4์ด ์ ์ด ์ Range ๋๋ Cells ์ฌ์ฉ
Range("B4").Select
: B4์
์ ํฌ์ปค์ค ์ฃผ๊ธฐ
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Select Case Target.Column
Case 2, 3, 4, 5
If Target.Column = 2 And Target.Row = 7 Then
Range("B" & (Target.Value + 9)).Select
Cells((Target.Value + 9), "B").Select
End If
Case Else
Exit Sub
End Select
End Sub
4. ๋ง์ฐ์ค ์ด๋ฒคํธ
- ์๋์ ๊ฐ์ด ๋๋ธ ํด๋ฆญ, ์ค๋ฅธ์ชฝ ๋ง์ฐ์ค ํด๋ฆญ ๋ฑ์ ์ด๋ฒคํธ๋ฅผ ์ค์ ํ ์ ์์
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
(๋ด์ฉ ์
๋ ฅ)
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
(๋ด์ฉ ์
๋ ฅ)
End Sub
4-1. ํ์ฉ ์์
- 10~14์ด์ ๋ํด ์ฐํด๋ฆญ ์ ๋ฐฐ๊ฒฝ์ ๋ณ๊ฒฝ ์ด๋ฒคํธ ์ ์ฉ
- 15์ด์ ๋ํด ์ฐํด๋ฆญ ์ "O","X" ํ ๊ธ ์ด๋ฒคํธ ์ ์ฉ
- 1~9ํ์ ์ค๋ฅธ์ชฝ ๋ง์ฐ์ค๋ฅผ ํด๋ฆญํด๋ ๋ฐ์ํ์ง ์๋๋ก ์ฒ๋ฆฌ
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Select Case Target.Column
Case 10, 11, 12, 13, 14, 15
If Target.Row < 10 Then '1~9ํ์ Exit Sub
Exit Sub
End If
Case Else '10~15์ด์ด ์๋๋ฉด Exit Sub
Exit Sub
End Select
Select Case Target.Column
Case 10, 11, 12, 13, 14 '๋ฐฐ๊ฒฝ์ ๋ณ๊ฒฝ
If Target.Interior.Color = RGB(153, 153, 255) Then
Target.Interior.Color = RGB(255, 255, 255)
Else
Target.Interior.Color = RGB(153, 153, 255)
End If
Case 15 'O,X ๋ณ๊ฒฝ
If Target.Value = "O" Then
Target.Value = "X"
Else
Target.Value = "O"
End If
Case Else
Exit Sub
End Select
End Sub
5. ์ธ๋ถ ํ๋ก๊ทธ๋จ ํธ์ถ
5-1. ํ
์คํธ ํ์ผ ์ด๊ธฐ
Dim filePath As String
Dim fileName As String
Dim progPath As String
filePath = "y:\๊ฒฝ๋ก1\๊ฒฝ๋ก1-1\"
fileName = filePath & Target.Value & ".sql"
If Dir(fileName) = "" Then '์ค์ ํ ๊ฒฝ๋ก์ ํด๋น ํ์ผ์ด ์๋ ๊ฒฝ์ฐ
Exit Sub
Else
Workbooks.Open fileName:=fileName 'ํ์ผ์ด ์กด์ฌํ๋ฉด ์ด๊ธฐ
End If
progPath = "C:\Users\YNJCH\AppData\Local\Programs\Microsoft VS Code\Code.exe" '์คํ์ํฌ ํ์ผ ๊ฒฝ๋ก
progPath = "notepad.exe" '์คํ์ํฌ ํ์ผ ๊ฒฝ๋ก
Proc = Shell(progPath & " " & fileName, vbNormalFocus) 'ํ์ผ ์คํ!!
5-2. Excel ํ์ผ ์ด๊ธฐ
Dim filePath As String
Dim fileName As String
filePath = "y:\๊ฒฝ๋ก1\๊ฒฝ๋ก1-1\"
fileName = filePath & "Excel.xlsx"
If Dir(fileName) = "" Then '์ค์ ํ ๊ฒฝ๋ก์ ํด๋น ํ์ผ์ด ์๋ ๊ฒฝ์ฐ
Exit Sub
Else
Workbooks.Open fileName:=fileName 'ํ์ผ์ด ์กด์ฌํ๋ฉด ์ด๊ธฐ
End If
5-3. Excel ํ์ผ๋ช
๊ฐ์ ธ์ค๊ธฐ
- For ๋ฌธ์ผ๋ก ์ ํํ ์
์ ํ๊ณผ ๊ทธ ์ดํ 3๊ฐ ํ์ ๊ฐ์ ํ์ธ
Dir("A*.xlsx")
: A๋ก ์์ํ๋ Excel ํ์ผ์ ๊ฐ์ ธ์ด
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Dim abbName As String
Dim fileName As String
Dim filePath As String
Dim idx As Integer
Select Case Target.Column
Case 7 '์ ํํ ์
์ด G์ด์ธ ๊ฒฝ์ฐ For ๋ฌธ ์์
For i = Target.Row To Target.Row + 3
filePath = "y:\๊ฒฝ๋ก1\๊ฒฝ๋ก1-1\"
fileName = "" 'ํ์ผ๋ช
๋ณ์๋ ๋น๊ฐ์ผ๋ก ์ ์ธ
If Len(Cells(i, "F").Value) > 0 Then 'F์ด์ iํ์ ๊ฐ์ด ์๋ ๊ฒฝ์ฐ Excel ํ์ผ๋ช
๊ฐ์ ธ์ค๊ธฐ
fileName = Dir(filePath & Cells(i, "F").Value & "*.xlsx")
End If
Cells(i, "Q") = Left(Right(fileName, 16), 11)
Next i
Case Else
Exit Sub
End Select
End Sub