Function Procedure - Heeyoung-Ahn/Excel_VBA GitHub Wiki
Function Procedure
- ํ๋ก์์ ๋ด ์ฝ๋๋ฅผ ์คํํ๊ณ ๊ฒฐ๊ณผ๊ฐ์ ๋ฐํ
(์ฐธ์กฐ) Sub Procedure: ํ๋ก์์ ์ ์ฝ๋๋ฅผ ์คํ
- ํ๋ก์์ ์ ๊ตฌ๋ฌธ์ Function Procedure ์ด๋ฆ์ผ๋ก ๊ฐ์ ๋ฐํํ๋ ์ฝ๋๊ฐ ํฌํจ๋์ด ์์ด์ผ ํจ
- Function Procedure๋ ์ํฌ์ํธ ๋๋ ๋ค๋ฅธ ํ๋ก์์ ์์ ์ฌ์ฉํ ์ ์์
- ์๋ต๊ฐ๋ฅํ ์ธ์๋ Optional๋ก ์ ์ธํ๋ฉฐ ์๋ตํ ๊ฒฝ์ฐ์ ๊ธฐ๋ณธ๊ฐ์ ์ง์ ํด์ผ ํจ
- ByVal vs. ByRef
- Sample
Option Explicit
Function listCustomer(rngDB As Range, Optional lngAmt As Long = 100) As String
Dim strCustomer As String
Dim rng As Range
Application.Volatile False
For Each rng In rngDB
If rng.Value >= lngAmt Then
strCustomer = strCustomer & rng.Offset(0, -1).Value & ", "
End If
Next rng
If Len(strCustomer) > 0 Then
listCustomer = Left(strCustomer, Len(strCustomer) - 2)
Else
listCustomer = vbNullString
End If
End Function
Sub callFunctionTest(rngA As Range, lngA As Long)
MsgBox listCustomer(rngA, lngA)
End Sub
Sub callSubTest()
Call callFunctionTest(Range(โB2โ, Cells(Rows.Count, 2).End(xlUp)), 100)
End Sub