VBA 프로그래밍의 기초

Similar documents
歯엑셀모델링

[ASP: 그림 2-2] date.asp 실행결과 DateAdd 지정된날짜에시간을추가하거나뺀새로운날짜를반환한다. 구문 : DateAdd(interval, number, date) interval : 필수적인인수로 interval 을추가한날짜를나타내는문자식이다. 그값에대

Hanyang Volunteer Corps volunteer image

06.._ _12...._....

F.

06³â_±â»ÝÀÇ»ù_10¿ùÈ£_À¥Áø


¼�¼úÇüÁßÇг»Áö2µµ

y 0.5 9, 644 e = 10, y = ln = 3.6(%) , May. 20, 2005

(Microsoft PowerPoint - 2\300\345.ppt)

PowerPoint 프레젠테이션

HWP Document

기본문법1

???? 1

C++-¿Ïº®Çؼ³10Àå

해양모델링 2장5~ :26 AM 페이지6 6 오픈소스 소프트웨어를 이용한 해양 모델링 물리적 해석 식 (2.1)의 좌변은 어떤 물질의 단위 시간당 변화율을 나타내며, 우변은 그 양을 나타낸 다. k 5 0이면 C는 처음 값 그대로 농

12-file.key

Microsoft Word - 강의록1.doc

1

윈도우즈프로그래밍(1)

Microsoft PowerPoint - Computer - chapter04.ppt [호환 모드]

遺꾨떦?쒖?532.ps, page Normalize

遺꾨떦?쒖? 540.ps, page Normalize

歯9장.PDF

遺꾨떦?쒖?526.ps, page Normalize

02 而щ읆.ps, page Normalize

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

10주차.key

遺꾨떦?쒖?525.ps, page Normalize

Modern Javascript

歯처리.PDF

Visual Basic 반복문


PowerPoint 프레젠테이션

분당표지522.ps, page Normalize

Javascript.pages

01 遺꾨떦?쒖?544.ps, page Normalize

Week5

분당표지 516.ps, page Normalize

歯VB강좌5.PDF

HW5 Exercise 1 (60pts) M interpreter with a simple type system M. M. M.., M (simple type system). M, M. M., M.

T100MD+

Microsoft PowerPoint - e pptx

EBS-PDF컴퓨터일반-07-오

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

분당표지518.ps, page Normalize

遺꾨떦?쒖?530.ps, page Normalize

USB2

EBS직탐컴퓨터일반-06-OK

07 자바의 다양한 클래스.key

슬라이드 1

untitled

untitled

슬라이드 1

Let G = (V, E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a set of E, possibly empty, that is includ

<32B1B3BDC32E687770>

untitled

기초컴퓨터프로그래밍

학습목표 배열에대해서안다. 언어통합질의 (LINQ) 에대해서안다. 2

chap 5: Trees

서울의 바람 wind+want 일 시 3.9(수)~5.8(일) 09:00~18:00 장 소 서울시청 8층 하늘광장 갤러리 문 의 입장료 내 용 재개발의 바람, 금전적인 욕망, 건강에 대한 개인적인 소망

chap7.key

sms_SQL.hwp

학습목표 함수프로시저, 서브프로시저의의미를안다. 매개변수전달방식을학습한다. 함수를이용한프로그래밍한다. 2


5.스택(강의자료).key

K&R2 Reference Manual 번역본

9


텀블러514

+변협사보 4월호

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

목차 BUG 문법에맞지않는질의문수행시, 에러메시지에질의문의일부만보여주는문제를수정합니다... 3 BUG ROUND, TRUNC 함수에서 DATE 포맷 IW 를추가지원합니다... 5 BUG ROLLUP/CUBE 절을포함하는질의는 SUBQUE

Çмú´ëȸ¿Ï¼º

2012³â8¿ùÈ£˙ȸš

1..

Orcad Capture 9.x

1차내지

RYWKVGWKJOFY.hwp

......

13주-14주proc.PDF

untitled

PowerSHAPE 따라하기 Calculate 버튼을 클릭한다. Close 버튼을 눌러 미러 릴리프 페이지를 닫는다. D 화면을 보기 위하여 F 키를 누른다. - 모델이 다음과 같이 보이게 될 것이다. 열매 만들기 Shape Editor를 이용하여 열매를 만들어 보도록

PowerChute Personal Edition v3.1.0 에이전트 사용 설명서

PL10

untitled

<30352D30312D3120BFB5B9AEB0E8BEE0C0C720C0CCC7D82E687770>

歯mp3사용설명서

8장 문자열

CAD 화면상에 동그란 원형 도형이 생성되었습니다. 화면상에 나타난 원형은 반지름 500인 도형입니다. 하지만 반지름이 500이라는 것은 작도자만 알고 있는 사실입니다. 반지름이 500이라는 것을 클라이언트와 작업자들에게 알려주기 위 해서는 반드시 치수가 필요하겠죠?

MAX+plus II Getting Started - 무작정따라하기

*세지6문제(306~316)OK

歯MDI.PDF

Tcl의 문법

6주차.key

<BACFC7D1B3F3BEF7B5BFC7E22D3133B1C733C8A BFEB2E687770>


OCaml

UI TASK & KEY EVENT

4 CD Construct Special Model VI 2 nd Order Model VI 2 Note: Hands-on 1, 2 RC 1 RLC mass-spring-damper 2 2 ζ ω n (rad/sec) 2 ( ζ < 1), 1 (ζ = 1), ( ) 1

Transcription:

VBA? VBA. VBA. VBA. 4.x VBA VBA. VBA VBA. VBA,. VBA VBA. VBA., VBA. VBA (,, ). VBA.,. VBA,,. VBA,,,.

VBA,,...,. VBA.. VBA.

VBA. VBA......

. B2..... Sub Macro1() ' ' Macro1 Macro ' pp () 2005-01-14 ' Range("B2").Select ActiveCell.FormulaR1C1 = " " Range("B2").Select Columns("B:B").EntireColumn.AutoFit With Selection.HorizontalAlignment = xlcenter.verticalalignment = xlcenter.wraptext = False.Orientation = 0.AddIndent = False.IndentLevel = 0.ShrinkToFit = False.ReadingOrder = xlcontext.mergecells = False End With With Selection.Font.Name = "".FontStyle = "".Size = 10.Strikethrough = False.Superscript = False.Subscript = False.OutlineFont = False.Shadow = False.Underline = xlunderlinestylenone.colorindex = xlautomatic End With Selection.Borders(xlDiagonalDown).LineStyle = xlnone Selection.Borders(xlDiagonalUp).LineStyle = xlnone

Selection.Borders(xlEdgeLeft).LineStyle = xlnone With Selection.Borders(xlEdgeTop).LineStyle = xldash.weight = xlthin.colorindex = 46 End With With Selection.Borders(xlEdgeBottom).LineStyle = xldouble.weight = xlthick.colorindex = 46 End With Selection.Borders(xlEdgeRight).LineStyle = xlnone With Selection.Interior.ColorIndex = 15.Pattern = xlsolid.patterncolorindex = xlautomatic End With End Sub VBA. VBA. VBA..... VBA. VBA.

VBA....

Sub Option1() Dim payoff Dim k Dim s Dim p Dim response As Double As Double As Double As Double As String p = 3000 k = 20000 payoff = payoff - p response = InputBox(" ",, k) If Len(response) = 0 Then Exit Sub s = CDbl(response) If s > k Then payoff = payoff + s - k End If MsgBox "Payoff is " & payoff End Sub Function VanillaPayoff(iOpt As Integer, s As Double, x As Double) If iopt = 1 Then VanillaPayoff = Max(s - x, 0) ElseIf iopt = -1 Then VanillaPayoff = Max(x - s, 0) End If End Function

Sub Option1() Dim payoff Dim k Dim s Dim p Dim response p = 3000 k = 20000 payoff = payoff - p As Double As Double As Double As Double As String response = InputBox(" ",, k) If Len(response) = 0 Then Exit Sub s = CDbl(response) If s > k Then payoff = payoff + s - k End If MsgBox "Payoff is " & payoff End Sub

Dim Arr1(10) As Double Dim Arr2(5) As Long Dim Arr3(1 To 10) As Double Dim Arr4(2 To 5) As Long Dim Arr5() As Double ReDim Arr5(11) Sub Historical_Volatility() Dim closeprice() As Double Dim yld() As Double Dim i As Long Dim stdev As Double Dim yld_year As Double ReDim closeprice(1 To 11) ReDim yld(2 To 11) closeprice(1) = 969 closeprice(2) = 989 closeprice(3) = 995 closeprice(4) = 957 closeprice(5) = 915 closeprice(6) = 880 closeprice(7) = 858 closeprice(8) = 859 closeprice(9) = 848 closeprice(10) = 836 closeprice(11) = 845

For i = LBound(closeprice) + 1 To UBound(closeprice) yld(i) = Log(closeprice(i) / closeprice(i - 1)) Next stdev = Application.WorksheetFunction.stdev(yld()) yld_year = stdev * Sqr(52) Debug.Print Format(stdev, "0.00%") Debug.Print Format(yld_year, "0.00%") End Sub LBound(Arr3) 1 UBound(Arr3) 10 LBound(Arr4) 2 UBound(Arr4) 5,,.

Sub demo_comparison_operators1() Debug.Print 1 > 2 'False. Debug.Print 3 < 4 'True. Debug.Print 5 <> 6 'True. End Sub Sub demo_comparison_operators2() Debug.Print "A" > "a" 'False. Debug.Print "A" < "B" 'True. Debug.Print "A" <> "a " 'True. End Sub

1.IF THEN ELSE A -21. If A>0 Then A. -21 0 If A>0 Then Then (MsgBox A is greater than zero ) ElseIf A<0 Then.

2.SELECT CASE Case 1 To 4, 7 To 9, 11, 13, Is >

1.FOR...NEXT Sub Historical_Volatility() Dim closeprice() As Double Dim yld() As Double Dim i As Long Dim stdev As Double Dim yld_year As Double ReDim closeprice(1 To 11) ReDim yld(2 To 11) closeprice(1) = 969 closeprice(2) = 989 closeprice(3) = 995 closeprice(4) = 957 closeprice(5) = 915 closeprice(6) = 880 closeprice(7) = 858 closeprice(8) = 859 closeprice(9) = 848 closeprice(10) = 836 closeprice(11) = 845 For i = LBound(closeprice) + 1 To UBound(closeprice) yld(i) = Log(closeprice(i) / closeprice(i - 1)) Next stdev = Application.WorksheetFunction.stdev(yld()) yld_year = stdev * Sqr(52)

Debug.Print Format(stdev, "0.00%") Debug.Print Format(yld_year, "0.00%") End Sub

2.FOR EACH IN~NEXT

3.DO...LOOP Do While~Loop (True) (False). Do Until~Loop (True). Do~Loop While (True) (False).

Do~Loop Until (True). Do~Loop. Do~Loop. Exit Do.

StrComp() Sub demostrcomp() Dim MyStr1 As String Dim MyStr2 As String MyStr1 = "ABCD" MyStr2 = "abcd" 'Text, 0 MsgBox StrComp(MyStr1, MyStr2, 1) ', -1 MyStr1 MyStr2. MsgBox StrComp(MyStr1, MyStr2, 0) ' Option Compare. MsgBox StrComp(MyStr1, MyStr2) End Sub

StrConv( ) Sub demostrconv() MsgBox StrConv("upper case", vbuppercase) MsgBox StrConv("LOWER CASE", vblowercase) MsgBox StrConv("proper case", vbpropercase) MsgBox StrConv("wide", vbwide) MsgBox StrConv("", vbnarrow) End Sub Len( )

If TestStr= Then End If If Len(TestStr)=0 Then End If Sub demolen() MsgBox Len("ABCD") MsgBox Len("AB CD") MsgBox Len("") End Sub Format( )

InStr( ) InStr InStr (1, "Tech on the Net", "the") 9. InStr ("Tech on the Net", "the") 9. InStr (10, "Tech on the Net", "t") 15. Left( )

MsgBox Left( This is a Test,2) Mid( ) MsgBox Mid( This is a Test, 6, 2) Right( ) MsgBox Right( This is a Test, 2) LTrim, Trim, RTrim Sub demotrim() MsgBox LTrim(" This is a test. ") MsgBox Trim(" This is a test. ") MsgBox RTrim(" This is a test. ") End Sub

<-Date > Sub demopresent()

Dim a As Date a = Now MsgBox a a = Date MsgBox a a = Time MsgBox a End Sub Sub demoadjustsystemclock() Date = #8/23/98# Time = #12:00:00 AM# MsgBox Now End Sub Sub demodatevalue( ) MsgBox DateValue(Now) End Sub Sub demotimevalue( ) MsgBox TimeValue(Now) End Sub

Sub demodatefunctions() MsgBox Year(Now) MsgBox Month(Now) MsgBox Day(Now) MsgBox Hour(Now) MsgBox Minute(Now) MsgBox Second(Now) End Sub

Sub demoweekday() Select Case WeekDay(Now) Case vbsunday MsgBox "Today is Sunday" Case vbmonday MsgBox "Today is Monday" Case vbtuesday MsgBox "Today is Tuesday" Case vbwednesday MsgBox "Today is Wednesday" Case vbthursday MsgBox "Today is Thursday" Case vbfriday MsgBox "Today is Friday" Case vbsaturday MsgBox "Today is Saturday" End Select End Sub Sub demodatepart() MsgBox DatePart("yyyy", Now) MsgBox DatePart("q", Now) MsgBox DatePart("m", Now) MsgBox DatePart("y", Now) MsgBox DatePart("d", Now) MsgBox DatePart("w", Now) MsgBox DatePart("ww", Now) MsgBox DatePart("h", Now)

MsgBox DatePart("n", Now) MsgBox DatePart("s", Now) End Sub Sub demodateserial() Dim dtedate As Date dtedate = DateSerial("2002", "5", "19") Debug.Print dtedate End Sub

Sub demodateadd() Dim OneYearLater As Date OneYearLater = DateAdd("yyyy", 1, Now) Select Case WeekDay(OneYearLater) Case vbsunday MsgBox "This day of the next year is Sunday"

Case vbmonday MsgBox "This day of the next year is Monday" Case vbtuesday MsgBox "This day of the next year is Tuesday" Case vbwednesday MsgBox "This day of the next year is Wednesday" Case vbthursday MsgBox "This day of the next year is Thursday" Case vbfriday MsgBox "This day of the next year is Friday" Case vbsaturday MsgBox "This day of the next year is Saturday" End Select End Sub Sub demodatediff() Dim TheDate As Date TheDate = InputBox("Enter a date") MsgBox "Days from today: " & DateDiff("d", Now, TheDate) End Sub Sub demodatediff1() MsgBox DateDiff("h", #10:00:00 AM#, #12:59:59 PM#) End Sub

Sub demodatediff2() MsgBox DateDiff("m", #7/30/98#, #8/1/98#) End Sub

Sub demoatan( ) MsgBox "(PI) " & 4 * Atn(1) & "" End Sub

Dim hfile As Long hfile=freefile

Open "TESTFILE" For Input As #1 '. Close #1 Open "TESTFILE" For Output Shared As #1 '. Close #1 Open "TESTFILE" For Binary Access Write As #1 '. Close #1

Open "TESTFILE" For Binary Access Read Lock Read As #1 Input Input. TESTFILE. Dim MyChar Open "TESTFILE" For Input As #1 '. Do While Not EOF(1) '. MyChar = Input(1, #1) '. Debug.Print MyChar '. Loop Close #1 '. input# Dim ifilenum As Integer Dim strname, strnumber, strdepart ' ifilenum = FreeFile

' person.txt Open "Person.txt" For Input As ifilenum ' Input #ifilenum, strname, strnumber, strdepart ' txtname.text = strname : txtnumber.text = strnumber : txtdepart.text = strdepart Close ifilenum Line Input # Sub demo_lineinput() 'Open EOF. ' Close. ' Line Input #. 'File_Data. 'Line Input #. ' vbcrlf. '. 'Line Input # Print #. 'File_Data [ ]. Dim File_Line Dim File_Data Dim fn As String As String As Long fn = FreeFile '. Open "test.txt" For Input As #fn '. Do While Not EOF(fn) Line Input #fn, File_Line File_Line = File_Line & vbcrlf File_Data = File_Data & File_Line Loop

'. Close #fn '. Debug.Print File_Data End Sub Print # Sub demo_print() Open "TESTFILE.txt" For Output As #1 '. Print #1, "This is a test" '. Print #1, '. Print #1, "Zone 1"; Tab; "Zone 2" '. Print #1, "Hello"; " "; "World" '. Print #1, Spc(5); "5 leading spaces " ' 5. Print #1, Tab(10); "Hello" ' 10. ' Boolean, Date, Null Error. Dim MyBool, MyDate, MyNull, MyError MyBool = False MyDate = #2/12/1969# MyNull = Null MyError = CVErr(32767) ' True, False, Null Error '. Print #1, MyBool; " is a Boolean value" Print #1, MyDate; " is a date" Print #1, MyNull; " is a null value" Print #1, MyError; " is an error value" Close #1 ' End Sub Write #

Sub demo_write() Open "TESTFILE.txt" For Output As #1 '. Write #1, "Hello World", 234 '. Write #1, '. Dim MyBool, MyDate, MyNull, MyError ' Boolean, Date, Null Error. MyBool = False MyDate = #2/12/1969# MyNull = Null MyError = CVErr(32767) ' Boolean #TRUE# #FALSE#. '. #1994-07-13# ' 1994 7 13. Null #NULL#. ' Error #ERROR errorcode#. Write #1, MyBool; " is a Boolean value" Write #1, MyDate; " is a date" Write #1, MyNull; " is a null value" Write #1, MyError; " is an error value" Close #1 End Sub '. Dim FileLength Open "TESTFILE" For Input As #1 '. FileLength = LOF(1) '. Close #1 '. MySize = FileLen("TESTFILE") ' ()

Dim InputData Open "MYFILE" For Input As #1 '. Do While Not EOF(1) '. Line Input #1, InputData '. Debug.Print InputData '. Loop Close #1 '. filetoopen = Application.GetOpenFilename("Text Files (*.txt), *.txt") If filetoopen <> False Then

MsgBox "Open " & filetoopen End If <- >

<- > Sub () Dim sht As Worksheet

Dim col As Long Dim s Dim k Dim T Dim r Dim v Dim d1 Dim d2 Dim c As Double As Double As Double As Double As Double As Double As Double As Double col = 3 Set sht = Sheet1 s = Sheet1.Cells(16, col).value k = Sheet1.Cells(17, col).value r = Sheet1.Cells(18, col).value T = Sheet1.Cells(19, col).value v = Sheet1.Cells(20, col).value d1 = Log(s / k) + (r + Application.WorksheetFunction.Power(v, 2) * 0.5) * T d1 = d1 / (v * Sqr(T)) d2 = d1 - v * Sqr(T) With Application.WorksheetFunction c = s *.NormSDist(d1) - k * Exp(-r * T) *.NormSDist(d2) End With Sheet1.Cells(22, col) = c End Sub Dim sht As Worksheet Set sht = Sheet1

<- > Dim col As Long

col = 3 s = Sheet1.Cells(16, col) k = Sheet1.Cells(17, col) r = Sheet1.Cells(18, col) T = Sheet1.Cells(19, col) v = Sheet1.Cells(20, col) Sheet1.Cells(22, col) = c

<- >

/