SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
ほんのすこしの僕のExcelマクロ
                               中尾光輝
                           2012-02-17




   DatabaseCuration勉強会1 「Excelのあるくらし」 http://www.dbcuration.info/ibento/
2012年2月17日金曜日                                                              1
マクロを知らない
                で苦しんでいる人
                向けにちょっとし
                たマクロの使い方
                を紹介します



2012年2月17日金曜日              2
データ取り出しに難儀している人向けに、

      CSVに書き出さないでファイルの中の

      データを取得する方法を紹介します




2012年2月17日金曜日               3
心に留めておく事




2012年2月17日金曜日              4
CSVはRFC4180に仕様があるの
         だが、それ以前に独自実装が先行
         していたので、ソフトウェア間で
         のファイル互換性に乏しい。




2012年2月17日金曜日                 5
は 人生はあま りにも短い。
 何 かを憎むに




2012年2月17日金曜日                    6
現状を愛す。




2012年2月17日金曜日            7
とても大事な
                   キミの想いは
                  無駄にならない 
                    世界は廻る
                (中田ヤスタカ 2007)




2012年2月17日金曜日                   8
先行研究
       • デフォルトデータフォーマット変換による遺伝子名
            などの日付化と指数化、その公共DBへの波及




2012年2月17日金曜日                       9
マクロ




2012年2月17日金曜日   10
VBの編集と実行

                • 開発メニュー
                • エディター
                • マクロの記録


2012年2月17日金曜日                11
セルの指定
        Sub	
  セルの値を取得するセルに値をセットする()
        	
  	
  	
  	
  MsgBox	
  (Cells(1,	
  "A").Value)
        	
  	
  	
  	
  Cells(1,	
  "A").Value	
  =	
  Cells(1,	
  "A").Value	
  *	
  2
        End	
  Sub

        Sub	
  型エラー()
        	
  	
  	
  	
  MsgBox	
  (Cells(1,	
  "C").Value	
  +	
  "["	
  +	
  Cells(1,	
  "A").Value	
  +	
  "]")
        End	
  Sub

        Sub	
  数値を文字列に変換する、文字列を結合する()
        	
  	
  	
  	
  MsgBox	
  (Cells(1,	
  "C").Value	
  +	
  "["	
  +	
  CStr(Cells(1,	
  "A").Value)	
  +	
  "]")
        	
  	
  	
  	
  Cells(1,	
  "D").Value	
  =	
  Cells(1,	
  "C").Value	
  +	
  "["	
  +	
  CStr(Cells(1,	
  "A").Value)	
  +	
  "]"
        End	
  Sub

        Sub	
  数式をつかう()
        	
  	
  	
  	
  Cells(1,	
  "E").Formula	
  =	
  "=B1	
  -­‐	
  A1"
        End	
  Sub




2012年2月17日金曜日                                                                                                                                12
文字列の置換
         Sub 初期値()                                               Sub セル内改行を消す()
           Cells(1, "A").Value = "ATTATTA"                         Dim str As String
         End Sub                                                   str = Cells(3, "A").Value
                                                                   Cells(3, "A").Value = Replace(str, vbCr, " ")
         Sub 置換()                                                End Sub
           Dim str As String
           str = Cells(1, "A").Value                             Sub LFはセル内改行しない()
           MsgBox (str)                                            Dim str As String
           Cells(2, "A").Value = Replace(str, "A", "a")            str = Cells(1, "A").Value
         End Sub                                                   MsgBox (str & vbLf & str)
                                                                   Cells(3, "A").Value = str & vbLf & str
         Sub タブ文字列()                                             End Sub
           Dim str As String
           str = Cells(1, "A").Value                             Sub CRLF()
           MsgBox (str & vbTab & str)                              Dim str As String
         End Sub                                                   str = Cells(1, "A").Value
                                                                   MsgBox (str & vbCrLf & str)
         Sub CRとセル内改行()                                            Cells(3, "A").Value = str & vbCrLf & str
           Dim str As String                                     End Sub
           str = Cells(1, "A").Value
           Cells(3, "A").Value = str & vbCr & str & vbCr & str
         End Sub




2012年2月17日金曜日                                                                                                      13
くりかえし、For文
                Sub	
  くりかえし()

                	
  	
  	
  	
  Dim	
  i	
  As	
  Integer
                	
  	
  	
  	
  For	
  i	
  =	
  1	
  To	
  10
                	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "A")	
  =	
  i
                	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "B")	
  =	
  i	
  *	
  i
                	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "C")	
  =	
  i	
  +	
  i
                	
  	
  	
  	
  Next	
  i
                End	
  Sub




2012年2月17日金曜日                                                                          14
IF文、論理式
                Sub	
  IF文()

                	
  	
  	
  	
  Dim	
  i	
  As	
  Integer
                	
  	
  	
  	
  For	
  i	
  =	
  1	
  To	
  10
                	
  	
  	
  	
  	
  	
  	
  	
  If	
  (Cells(i,	
  "A").Value	
  Mod	
  2)	
  =	
  0	
  Then
                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "D").Value	
  =	
  "偶数"

                	
  	
  	
  	
  	
  	
  	
  	
  End	
  If
                	
  	
  	
  	
  Next	
  i
                End	
  Sub




2012年2月17日金曜日                                                                                                  15
応用1:SQL文を作成する
     Sub	
  INSERT文生成()

     	
  	
  	
  	
  Dim	
  i	
  As	
  Integer
     	
  	
  	
  	
  For	
  i	
  =	
  1	
  To	
  5
     	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "G").Value	
  =	
  "INSERT	
  INTO	
  genes	
  VALUES	
  ('"	
  &	
  _
     	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "A").Value	
  &	
  "',	
  "	
  &	
  _
     	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "B").Value	
  &	
  ",	
  "	
  &	
  _
     	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "C").Value	
  &	
  ",	
  "	
  &	
  _
     	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "'"	
  &	
  Cells(i,	
  "D").Value	
  &	
  "',	
  "	
  &	
  _
     	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Cells(i,	
  "E").Value	
  &	
  ",	
  "	
  &	
  _
     	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "'"	
  &	
  Cells(i,	
  "F").Value	
  &	
  "')"
     	
  	
  	
  	
  Next	
  i
     End	
  Sub




2012年2月17日金曜日                                                                                                                                                                                                                        16
応用2:リンク集をつくる


                • https://github.com/nakao/vb/blob/
                  master/KazusaAnnotation/
                  annotationHelper.vb




2012年2月17日金曜日                                         17
スクリプティング



2012年2月17日金曜日           18
MacRubyでExcel.appを操る




2012年2月17日金曜日                          19
RubyでExcelを操る

                • require spreadsheet
                • くわしくは、ruby excel spreadsheet
                 でGoogle検索




2012年2月17日金曜日                                    20
1. xlsファイルを開く

                2. セルの値を取得する

                3. セルに値をセットする

                4. セルの値を検証する




2012年2月17日金曜日                   21
phpでExcelを操る


                • php COMクラス



2012年2月17日金曜日                   22
Java から POI で Excel を操る




2012年2月17日金曜日                             23
まとめ

                • ほんのすこしのVBマクロで世界がひら
                 ける。

                • すべてのCSVを生まれる前に消し去りた
                 い、を実現するためのスクリプティング
                 を紹介した。



2012年2月17日金曜日                           24

Weitere ähnliche Inhalte

Kürzlich hochgeladen

ゲーム理論 BASIC 演習106 -価格の交渉ゲーム-#ゲーム理論 #gametheory #数学
ゲーム理論 BASIC 演習106 -価格の交渉ゲーム-#ゲーム理論 #gametheory #数学ゲーム理論 BASIC 演習106 -価格の交渉ゲーム-#ゲーム理論 #gametheory #数学
ゲーム理論 BASIC 演習106 -価格の交渉ゲーム-#ゲーム理論 #gametheory #数学ssusere0a682
 
2024年度 東京工業大学 工学院 機械系 大学院 修士課程 入試 説明会 資料
2024年度 東京工業大学 工学院 機械系 大学院 修士課程 入試 説明会 資料2024年度 東京工業大学 工学院 機械系 大学院 修士課程 入試 説明会 資料
2024年度 東京工業大学 工学院 機械系 大学院 修士課程 入試 説明会 資料Tokyo Institute of Technology
 
生成AIの回答内容の修正を課題としたレポートについて:お茶の水女子大学「授業・研究における生成系AIの活用事例」での講演資料
生成AIの回答内容の修正を課題としたレポートについて:お茶の水女子大学「授業・研究における生成系AIの活用事例」での講演資料生成AIの回答内容の修正を課題としたレポートについて:お茶の水女子大学「授業・研究における生成系AIの活用事例」での講演資料
生成AIの回答内容の修正を課題としたレポートについて:お茶の水女子大学「授業・研究における生成系AIの活用事例」での講演資料Takayuki Itoh
 
東京工業大学 環境・社会理工学院 建築学系 大学院入学入試・進学説明会2024_v2
東京工業大学 環境・社会理工学院 建築学系 大学院入学入試・進学説明会2024_v2東京工業大学 環境・社会理工学院 建築学系 大学院入学入試・進学説明会2024_v2
東京工業大学 環境・社会理工学院 建築学系 大学院入学入試・進学説明会2024_v2Tokyo Institute of Technology
 
世界を変えるクレーンを生み出そう! 高知エンジニアリングキャンプ2024プログラム
世界を変えるクレーンを生み出そう! 高知エンジニアリングキャンプ2024プログラム世界を変えるクレーンを生み出そう! 高知エンジニアリングキャンプ2024プログラム
世界を変えるクレーンを生み出そう! 高知エンジニアリングキャンプ2024プログラムKochi Eng Camp
 
次世代機の製品コンセプトを描く ~未来の機械を創造してみよう~
次世代機の製品コンセプトを描く ~未来の機械を創造してみよう~次世代機の製品コンセプトを描く ~未来の機械を創造してみよう~
次世代機の製品コンセプトを描く ~未来の機械を創造してみよう~Kochi Eng Camp
 

Kürzlich hochgeladen (6)

ゲーム理論 BASIC 演習106 -価格の交渉ゲーム-#ゲーム理論 #gametheory #数学
ゲーム理論 BASIC 演習106 -価格の交渉ゲーム-#ゲーム理論 #gametheory #数学ゲーム理論 BASIC 演習106 -価格の交渉ゲーム-#ゲーム理論 #gametheory #数学
ゲーム理論 BASIC 演習106 -価格の交渉ゲーム-#ゲーム理論 #gametheory #数学
 
2024年度 東京工業大学 工学院 機械系 大学院 修士課程 入試 説明会 資料
2024年度 東京工業大学 工学院 機械系 大学院 修士課程 入試 説明会 資料2024年度 東京工業大学 工学院 機械系 大学院 修士課程 入試 説明会 資料
2024年度 東京工業大学 工学院 機械系 大学院 修士課程 入試 説明会 資料
 
生成AIの回答内容の修正を課題としたレポートについて:お茶の水女子大学「授業・研究における生成系AIの活用事例」での講演資料
生成AIの回答内容の修正を課題としたレポートについて:お茶の水女子大学「授業・研究における生成系AIの活用事例」での講演資料生成AIの回答内容の修正を課題としたレポートについて:お茶の水女子大学「授業・研究における生成系AIの活用事例」での講演資料
生成AIの回答内容の修正を課題としたレポートについて:お茶の水女子大学「授業・研究における生成系AIの活用事例」での講演資料
 
東京工業大学 環境・社会理工学院 建築学系 大学院入学入試・進学説明会2024_v2
東京工業大学 環境・社会理工学院 建築学系 大学院入学入試・進学説明会2024_v2東京工業大学 環境・社会理工学院 建築学系 大学院入学入試・進学説明会2024_v2
東京工業大学 環境・社会理工学院 建築学系 大学院入学入試・進学説明会2024_v2
 
世界を変えるクレーンを生み出そう! 高知エンジニアリングキャンプ2024プログラム
世界を変えるクレーンを生み出そう! 高知エンジニアリングキャンプ2024プログラム世界を変えるクレーンを生み出そう! 高知エンジニアリングキャンプ2024プログラム
世界を変えるクレーンを生み出そう! 高知エンジニアリングキャンプ2024プログラム
 
次世代機の製品コンセプトを描く ~未来の機械を創造してみよう~
次世代機の製品コンセプトを描く ~未来の機械を創造してみよう~次世代機の製品コンセプトを描く ~未来の機械を創造してみよう~
次世代機の製品コンセプトを描く ~未来の機械を創造してみよう~
 

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

ほんのすこしの僕のExcelマクロ

  • 1. ほんのすこしの僕のExcelマクロ 中尾光輝 2012-02-17 DatabaseCuration勉強会1 「Excelのあるくらし」 http://www.dbcuration.info/ibento/ 2012年2月17日金曜日 1
  • 2. マクロを知らない で苦しんでいる人 向けにちょっとし たマクロの使い方 を紹介します 2012年2月17日金曜日 2
  • 3. データ取り出しに難儀している人向けに、 CSVに書き出さないでファイルの中の データを取得する方法を紹介します 2012年2月17日金曜日 3
  • 5. CSVはRFC4180に仕様があるの だが、それ以前に独自実装が先行 していたので、ソフトウェア間で のファイル互換性に乏しい。 2012年2月17日金曜日 5
  • 6. は 人生はあま りにも短い。 何 かを憎むに 2012年2月17日金曜日 6
  • 8. とても大事な キミの想いは 無駄にならない  世界は廻る (中田ヤスタカ 2007) 2012年2月17日金曜日 8
  • 9. 先行研究 • デフォルトデータフォーマット変換による遺伝子名 などの日付化と指数化、その公共DBへの波及 2012年2月17日金曜日 9
  • 11. VBの編集と実行 • 開発メニュー • エディター • マクロの記録 2012年2月17日金曜日 11
  • 12. セルの指定 Sub  セルの値を取得するセルに値をセットする()        MsgBox  (Cells(1,  "A").Value)        Cells(1,  "A").Value  =  Cells(1,  "A").Value  *  2 End  Sub Sub  型エラー()        MsgBox  (Cells(1,  "C").Value  +  "["  +  Cells(1,  "A").Value  +  "]") End  Sub Sub  数値を文字列に変換する、文字列を結合する()        MsgBox  (Cells(1,  "C").Value  +  "["  +  CStr(Cells(1,  "A").Value)  +  "]")        Cells(1,  "D").Value  =  Cells(1,  "C").Value  +  "["  +  CStr(Cells(1,  "A").Value)  +  "]" End  Sub Sub  数式をつかう()        Cells(1,  "E").Formula  =  "=B1  -­‐  A1" End  Sub 2012年2月17日金曜日 12
  • 13. 文字列の置換 Sub 初期値() Sub セル内改行を消す() Cells(1, "A").Value = "ATTATTA" Dim str As String End Sub str = Cells(3, "A").Value Cells(3, "A").Value = Replace(str, vbCr, " ") Sub 置換() End Sub Dim str As String str = Cells(1, "A").Value Sub LFはセル内改行しない() MsgBox (str) Dim str As String Cells(2, "A").Value = Replace(str, "A", "a") str = Cells(1, "A").Value End Sub MsgBox (str & vbLf & str) Cells(3, "A").Value = str & vbLf & str Sub タブ文字列() End Sub Dim str As String str = Cells(1, "A").Value Sub CRLF() MsgBox (str & vbTab & str) Dim str As String End Sub str = Cells(1, "A").Value MsgBox (str & vbCrLf & str) Sub CRとセル内改行() Cells(3, "A").Value = str & vbCrLf & str Dim str As String End Sub str = Cells(1, "A").Value Cells(3, "A").Value = str & vbCr & str & vbCr & str End Sub 2012年2月17日金曜日 13
  • 14. くりかえし、For文 Sub  くりかえし()        Dim  i  As  Integer        For  i  =  1  To  10                Cells(i,  "A")  =  i                Cells(i,  "B")  =  i  *  i                Cells(i,  "C")  =  i  +  i        Next  i End  Sub 2012年2月17日金曜日 14
  • 15. IF文、論理式 Sub  IF文()        Dim  i  As  Integer        For  i  =  1  To  10                If  (Cells(i,  "A").Value  Mod  2)  =  0  Then                        Cells(i,  "D").Value  =  "偶数"                End  If        Next  i End  Sub 2012年2月17日金曜日 15
  • 16. 応用1:SQL文を作成する Sub  INSERT文生成()        Dim  i  As  Integer        For  i  =  1  To  5                Cells(i,  "G").Value  =  "INSERT  INTO  genes  VALUES  ('"  &  _                                                                                Cells(i,  "A").Value  &  "',  "  &  _                                                                                Cells(i,  "B").Value  &  ",  "  &  _                                                                                Cells(i,  "C").Value  &  ",  "  &  _                                                                                "'"  &  Cells(i,  "D").Value  &  "',  "  &  _                                                                                Cells(i,  "E").Value  &  ",  "  &  _                                                                                "'"  &  Cells(i,  "F").Value  &  "')"        Next  i End  Sub 2012年2月17日金曜日 16
  • 17. 応用2:リンク集をつくる • https://github.com/nakao/vb/blob/ master/KazusaAnnotation/ annotationHelper.vb 2012年2月17日金曜日 17
  • 20. RubyでExcelを操る • require spreadsheet • くわしくは、ruby excel spreadsheet でGoogle検索 2012年2月17日金曜日 20
  • 21. 1. xlsファイルを開く 2. セルの値を取得する 3. セルに値をセットする 4. セルの値を検証する 2012年2月17日金曜日 21
  • 22. phpでExcelを操る • php COMクラス 2012年2月17日金曜日 22
  • 23. Java から POI で Excel を操る 2012年2月17日金曜日 23
  • 24. まとめ • ほんのすこしのVBマクロで世界がひら ける。 • すべてのCSVを生まれる前に消し去りた い、を実現するためのスクリプティング を紹介した。 2012年2月17日金曜日 24