▶  바로가기
 
           
코인니스 | 비온미디어 | 99Bitcoins(KOR) | 블록체인투데이 | 크립토뉴스 | 99Bitcoins(ENG) | 블록스트리트 | 블루밍비트 | 비인크립토 | 코인리더스 | 블록포스트 | CoinDesk | 코인뉴스전망대
주식갤러리 | 미국주식 | 창원개미TV | 주식포커나인 | 오선의 미국증시 | 매일경제 | 한국경제 | 서울경제 | 아주경제 | 머니투데이 | 헤럴드경제 | 아시아경제 | 파이낸셜뉴스 | 이데일리 | 이투데이 | 조선비즈
업비트 | 빗썸 | 네이버증권 | 트레이딩뷰 | 인베스팅닷컴 | 코인마켓캡 | 투게더아트 | 뮤직카우 | 핀고 | 카사 | 뱅카우 | 트레져러 | 펀더풀

'--- VBA 함수와 워크시트 함수

작성자 정보

  • 모아 작성
  • 작성일

컨텐츠 정보


본문

Option Explicit


'--- VBA 함수와 워크시트 함수

Sub Sample040()

    MsgBox VBA.Now

End Sub


'--- MsgBox 함수

Sub Sample041()

    Dim intKey As Integer

    intKey = MsgBox("작업을 계속하시겠습니까?", vbYesNo, "사용자 선택")

    If intKey = vbYes Then

        MsgBox "작업을 계속합니다."

    Else

        MsgBox "작업을 취소합니다."

    End If

End Sub


'--- InputBox 함수

Sub Sample042()

    Dim strPass As String

    

    Do

        strPass = InputBox("이름 입력: ", "사용자 확인", Application.UserName)

    Loop Until strPass <> ""

    

    MsgBox strPass & "님! 환영합니다."

End Sub


'--- InputBox 메서드

Sub Sample043()

    Dim varScore As Variant

    

    Do

        varScore = Application.InputBox("점수 입력(0~100)", Type:=1)

        If varScore = False Then Exit Sub

    Loop Until varScore >= 0 And varScore <= 100

    

    If varScore >= 80 Then

        MsgBox "합격입니다."

    Else

        MsgBox "불합격입니다."

    End If

End Sub


'--- InputBox 메서드로 셀 참조하기

Sub Sample044()

    Sheets("Sheet1").Select

    Dim rngCell As Range

    

    On Error Resume Next

    Set rngCell = Application.InputBox("셀 범위 지정", Type:=8)

    If rngCell Is Nothing Then Exit Sub

    

    rngCell.Interior.ColorIndex = 4

End Sub


'--- 데이터 형식 변환 함수

Sub Sample045()

    Dim strNum As String

    strNum = "7,243.836"

    

    MsgBox "String : " & vbTab & strNum & vbCr & _

               "CInt : " & vbTab & CInt(strNum) & vbCr & _

               "CDbl : " & vbTab & CDbl(strNum) & vbCr & _

               "CDate : " & vbTab & CDate(strNum)

End Sub


'--- 데이터 형식을 확인하는 함수

Sub Sample046()

    Dim strValue As String

    

    strValue = InputBox("판매금액 입력")

    If IsNumeric(strValue) Then

        MsgBox "최종 청구금액 : " & CCur(strValue) * 0.8

    Else

        MsgBox "판매금액 입력 오류"

    End If

End Sub


'--- Format 함수로 표시 형식 지정

Sub Sample047()

    MsgBox "123456 :" & vbTab & Format(123456, "#,##0원") & vbCr & _

               "12.456 :" & vbTab & Format(12.456, "0.00%") & vbCr & _

               "날짜 :" & vbTab & Format(Date, "m월 d일(AAA)") & vbCr & _

               "분기 :" & vbTab & Format(Date, "Q분기") & vbCr & _

               "대문자 :" & vbTab & Format("hello~", ">") & vbCr

End Sub


'--- 문자열 추출 함수

Sub Sample048()

    Dim strValue As String

    strValue = "Microsoft Office Excel"

    

    MsgBox "Left : " & vbTab & Left(strValue, 9) & vbCr & _

               "Right : " & vbTab & Right(strValue, 12) & vbCr & _

               "Mid : " & vbTab & Mid(strValue, 11, 6) & vbCr & _

               "Len : " & vbTab & Len(strValue)

End Sub


'--- 대소문자 변환 함수

Sub Sample049()

    Dim strValue As String

    strValue = "Microsoft Office Excel"

    

    MsgBox "Lcase : " & vbTab & LCase(strValue) & vbCr & _

               "Ucase : " & vbTab & UCase(strValue) & vbCr & vbCr & _

               "< : " & vbTab & Format(strValue, "<") & vbCr & _

               "> : " & vbTab & Format(strValue, ">")

End Sub


'--- 문자와 숫자의 상호 변환

Sub Sample050()

    Dim strValue As String, num As Double

    strValue = "25,000": num = 25000

    

    MsgBox "Val : " & vbTab & Val(strValue) & vbCr & _

               "CCur : " & vbTab & CCur(strValue) & vbCr & vbCr & _

               "Str : " & vbTab & Str(num) & vbCr & _

               "LTrim : " & vbTab & LTrim(Str(num))

End Sub


'--- 특정 문자열의 위치 계산

Sub Sample051()

    Sheets("Sheet2").Select

    Dim rngCell As Range, num As Integer

    For Each rngCell In Range("C3:C7")

        num = InStr(rngCell, ")")

        rngCell.Offset(0, 1) = "'" & Left(rngCell, num)

        rngCell.Offset(0, 2) = Mid(rngCell, num + 1)

    Next

End Sub


'--- 다른 문자열로 바꾸기

Sub Sample052()

    Sheets("Sheet3").Select

    Range("C3") = Replace(Range("B3"), vbLf, " ")

    Range("C4") = Replace(Range("B4"), " ", vbLf, Count:=1)

End Sub


'--- 숫자 처리 함수

Sub Sample053()

    Sheets("Sheet4").Select

    Dim rngCell As Range

    For Each rngCell In Range("B3:B8")

        rngCell.Offset(0, 1) = Int(rngCell)

        rngCell.Offset(0, 2) = Fix(rngCell)

        rngCell.Offset(0, 3) = CInt(rngCell)

        rngCell.Offset(0, 4) = Round(rngCell)

    Next

End Sub


'--- 현재 날짜와 현재 시간

Sub Sample054()

    MsgBox "현재 날짜 : " & vbTab & Date & vbCr & _

               "현재 시간 : " & vbTab & Time & vbCr & _

               "날짜/시간 : " & vbTab & Now

End Sub


'--- 날짜의 년, 월, 일

Sub Sample055()

    Dim date1 As Date, date2 As Date

    date1 = DateSerial(Year(Date), Month(Date) + 1, 0)

    date2 = DateSerial(Year(Date), Month(Date) + 1, 10)

    MsgBox "오늘 날짜 : " & vbTab & Date & vbCr & _

               "1차 청구일 : " & vbTab & date1 & vbCr & _

               "2차 청구일 : " & vbTab & date2

End Sub


'--- 날짜에 특정 시간 간격 더하기

Sub Sample056()

    Dim date1 As Date, date2 As Date

    date1 = DateAdd("m", 4, #10/31/2013#)

    date2 = DateAdd("m", -4, #10/31/2013#)

    MsgBox "기준 날짜 : " & vbTab & #10/31/2013# & vbCr & _

               "4개월 후 : " & vbTab & date1 & vbCr & _

               "4개월 전 : " & vbTab & date2

End Sub


'--- 날짜 간격 계산하기

Sub Sample057()

    Dim date1 As Date, date2 As Date

    Dim intYear As Integer, intMonth As Integer, intDay As Integer

    date1 = #10/15/2013#: date2 = #2/1/2014#

    

    intYear = DateDiff("yyyy", date1, date2)

    intMonth = DateDiff("m", date1, date2)

    intDay = DateDiff("d", date1, date2)

    MsgBox date1 & " 부터 " & date2 & " 까지" & vbCr & vbCr & _

               intYear & "년 " & intMonth & "개월 " & intDay & "일"

    

    intYear = DateDiff("m", date1, date2) / 12

    intMonth = DateDiff("m", date1, date2) Mod 12 - IIf(Day(date1) <= Day(date2), 0, 1)

    intDay = DateDiff("d", DateAdd("m", intYear * 12 + intMonth, date1), date2)

    MsgBox date1 & " 부터 " & date2 & " 까지" & vbCr & vbCr & _

               intYear & "년 " & intMonth & "개월 " & intDay & "일"

End Sub


'--- 배열에 값 지정하기

Sub Sample058()

    Dim intA As Integer, strMsg As String

    Dim Product As Variant, Price As Variant

    Product = Array("고등어", "갈치", "오징어")

    Price = Array(3000, 8000, 2500)

    

    For intA = 0 To UBound(Product)

        strMsg = strMsg & Product(intA) & vbTab & Format(Price(intA), "#,##0원") & vbCr

    Next

    MsgBox strMsg

End Sub


'--- 구분 기호로 배열에 값 지정하기

Sub Sample059()

    Dim intA As Integer, strMsg As String

    Dim Product As Variant, Price As Variant

    Product = Split("고등어,갈치,오징어", ",")

    Price = Split("3000,8000,2500", ",")

    

    For intA = 0 To UBound(Product)

        strMsg = strMsg & Product(intA) & vbTab & Format(Price(intA), "#,##0원") & vbCr

    Next

    MsgBox strMsg

End Sub


'--- 배열 값 연결하기

Sub Sample060()

    Sheets("Sheet5").Select

    Dim rngCell As Range, intA As Integer, Temp() As Variant

    

    For Each rngCell In Range("C3:C9")

        If rngCell >= 90 Then

            ReDim Preserve Temp(intA)

            Temp(intA) = rngCell.Offset(0, -1)

            intA = intA + 1

        End If

    Next

    

    MsgBox "90점 이상 : " & Join(Temp, " / ")

End Sub



포인트 선물 선물명단 선물하기

최소 5P ~ 최대 100000000P 까지 가능합니다.
로그인 후 선물하실 수 있습니다.

선물 받은 내용이 없습니다.


관련자료

댓글 0
등록된 댓글이 없습니다.

전체 336 / 1 페이지
번호
제목
이름

최근글


새댓글


알림 0
💬 포인트AD - 한줄 하루일상  출석체크  코인투자  주식투자  미술투자  음악투자  부동산투자  한우투자  명품투자  숙박투자  K-콘텐츠  에너지투자  기타투자