Home > Excel VBA Archive
Excel VBA Archive
VB as Interpreter computing
- 2008年6月28日 11:29
- Excel VBA
VBは行番号に沿って1行ずつコンパイルして実行処理されるプログラムです。Gotoステートメントで行を指定すれば行を飛ばしたり、戻ったり、ループさせることも出来ます。
VBに行番号をつけて簡単なコードを書いてみました。
1 times a=1 b=0 c=0 2 times a=3 b=2 c=0 3 times a=3 b=6 c=9
下のコードを実行するとイミディエイトウィンドウに上のように書き込まれます。最初に、a=0, b=0, c=0, i=1 と変数に数値を格納しておきます。インタプリタですので、1行ずつコードをコンパイルしながら処理されます。
1:a=0 の場合、行番号3に移動します
3:a=b+1 ---> a=0+1 ですので、a=1 となります
4:ここで、1 times a=1 b=0 c=0 と書き込まれます
5:a=1 の場合、行番号2 に移動します
2:b=2 となります
3:a=b+1 ---> a=2+1 ですので、a=3 となります
4:ここで、2 times a=3 b=2 c=0 と書き込まれます
5:a=3 となりましたので、行番号2には移動しません
6:b = a * 2 ですので、b=6 となります
7:c = a + b ですので、c=9 となります
8:ここで、3 times a=3 b=6 c=9 と書き込まれて終了です
- Comments: 0
- TrackBack (Close): 0
Declared Data Types & String function (型宣言文字&文字列関数のString型変換)
- 2008年6月28日 07:58
- Excel VBA
型宣言文字 型宣言文字はあまり推奨されないかもしれませんが、ここで紹介しているコードによく使ってますので紹介します。
| 宣言 | 型文字の使用例 | 宣言 | 型文字の使用例 |
|---|---|---|---|
| Dim x as Integer | Dim x% | Dim x as Long | Dim x& |
| Dim x as Single | Dim x! | Dim x as Double | Dim x# |
| Dim x as String | Dim x$ | Dim x As Currency | Dim x@ |
文字列関数のString型変換
| Variant型 | String型変換 | Variant型 | String型変換 |
|---|---|---|---|
| Chr() | Chr$() | ChrB() | ChrB$() |
| ChrW() | ChrW$() | Format() | Format$() |
| Mid() | Mid$() | MidB() | MidB$() |
| Right() | Right$() | Left() | Left$() |
| LeftB() | LeftB$() | LTrim() | LTrim$() |
| RTrim() | RTrim$() | Space() | Space$() |
| String() | String$() | Trim() | Trim$() |
| UCase() | UCase$() | LCase() | LCase$() |
Mid(Expression,Start,Length)-->Mid$(Expression as String,Start,Length)
Replace(Expression,Find, Replace,,)-->Replace$(Expression as String,Find, Replace,,)
上のテーブルのようにファンクションの"Mid"などで文字列を使うと決まっている場合は、Mid() -- > Mid$()と書くことでバリアント型からストリング型にバイト数を小さくした「型」を使うことで処理が速く(1)なります。Excel VBAでValueのついたデータ型(例:Textbox1.Value, Range("A1").Value など)はバリアント型です。VBAのコードを書く場合は、これらの計算をするときに必ず数値に変換させないとエラーの原因となります(Example:CSng(Textbox1.Value))。これは当然のことで、Valueの値に数値が入ったとしていてもバリアント型としてコンパイルされますので注意が必要です。これは数値でも他のデータ型に変換される可能性があるからです。
Spinbutton.Value ---> Long型 などの例外もあります。
(1)実行速度が速くなる理由はバイナリーデータ(機械語)にコンパイルした時の実行処理するときのサイズが小さくなるためです。Double型やLong型の計算よりも、Integer型の計算の方が速いのも同じ理由です。
コンピュータが認識できるのは2進数(0と1)のバイナリーデータです。電圧の高い=1, 低い=0のデータの組み合わせを認識して処理します。(ハードディスクドライブなどの記憶装置は、(普通に考えても)地球上にはS極とN極の磁気しかないのでそのバイナリーデータの組み合わせです。)
- Comments: 0
- TrackBack (Close): 0
Binary Search Function 2分検索ファンクション
2分検索ファンクションのVBAソースコードを紹介します。配列の最初から順番に目的の要素を探す場合は、最大でN回の比較検索が必要です。しかしこの2分検索アルゴリズムは最大でlog*N回の比較検索で探します。何度も言いますがソートなどの並び替えと同じく、アルゴリズムを構築する場合はとても長い配列を想定しなければいけません。
アルゴリズムとシステムについて:少し内容が逸れます。 アルゴリズムは「システム」とは違い失敗や漏れがあってはアルゴリズムとして成り立ちません。そういった理に適っている洗練されたアルゴリズムは人類のとても貴重な財産です。宝石やお金などの光り物は常に価値が変動したり時に失ったりすることがありますが、理となって顕現しているものは決して動いたり失うことがありません。不動の理(支点)がないと何も動かすことが出来ません。一方、ビジネスのツールや社会のルールとなるシステムは時間の経過と共にに想定外の事態が起こった場合、切捨てなければならない部分が生じます。株価の例を挙げると、上げ下げの材料は時間にほぼ比例するように増えていきます。
もしすべての条件を最初から想定できる社会システムを創ることが出来れば、公共の福祉(弱者救済)のための司法機関は必要なくなるでしょう。残念ながらシステムである以上それはありえません。通常、システムは常に多数を選択します。それでコツコツと(多数と少数の)鞘の部分に貯まりだす利益を生み出します。
話が逸れましたが、アルゴリズムはとても価値あるもので人生というジグソーパズルの中の定まった貴重なパーツにもなりうるということを理解してください。
The VBA source code of "Binary search" function is shown below.To find for the target element in an order from the beginning of array, N comparison search is required at the maximum. However, this "Binary search" algorithm will find target element at log*N time at the maximum. Although repeatedly said, when building an algorithm, you have to assume very long array.
About an algorithm and a system: The contents swerve for a while. Algorithm is different from "System", and bugs never occur in the algorithm. Such refined rational algorithms are human beings' very precious property. Although value jewelry or money may always fluctuate,and also may sometimes be lost, algorithm is truth and it will never change, or is not lost. Anything can be moved if there is no immovable truth (fulcrum). On the other hand, when the situation besides assumption happens to progress of time, the portion which must be cut off when produces the system used as the tool of business, or a social rule. If the example of a stock price is given, the material of taking up and down will increase mostly proportional to time.
The machinery of law for public welfare will become unnecessary if the social system which can assume all the conditions from the beginning can be predicted. Though regrettable, a system cannot be created perfectly like algorithm. Usually, a system always chooses a large number. After then, the profits (a large number and small number) which begin to accumulate in the portion of a difference are produced.
What I meant was, I want you to understand that an algorithm is very valuable and it can also become the fixed precious part of a jigsaw puzzle in your life.
ソースコードを紹介します。ヒープソートなどと比べるととても簡単なものです。
- Comments: 0
- TrackBack (Close): 0
ヒープソート・アルゴリズムの訂正・ Correction of HeapSort Algorithm
訂正:20%効率化されたヒープソート・アルゴリズムと書いていましたが、どうにも腑に落ちなかったので、C言語で書かれた専門書を買って調べたところ、ここに書いているコード(効率化されたヒープソートと書いたコードとほぼ同じもの)が本に書かれていました。
この記事の前に書いたヒープソートのコードは、Wikipediaや海外の複数のサイトで紹介されていたC言語のアルゴリズムを参考にしたものでした。それらが間違っているとは言い切れないし、難しいところです。ただ、効率化された新しいヒープソートと紹介した部分は間違っていますので、ここで訂正します。
簡単な時間測定で、通常のヒープソートよりも時間が短縮されます。コムソート11よりも少しだけ早くなりました。100万個の配列での相対的比較です。処理数は最低で13,815,511回となりますので単純計算で1万個の配列のソートテストを少なくとも150回して平均値を取ったのとほぼ同じになります。10,000,000*log(10,000,000)/10,000*log(10,000)=150(テストは乱数で作った配列の並び替えです)
アルゴリズム的には当然、O(N*log N) の範囲内での改善になります。コードは以下に紹介しています。
According to the HeapSort algorithm, the portion of the comparison & swap was all done in loop. I have removed the portion of compare & swap from the loop. As a result, large amounts of processings of sorting have been improved. New HeapSort is equivalent to CombSort11 or became more than it.
- Comments: 0
- TrackBack (Close): 0
Excel グラフを画像(GIF)データとして指定フォルダに作成&保存する(Create graph's image to folder)
- 2008年5月15日 13:18
- Excel VBA | GraphControl
エクセルのシート上のグラフをGIF画像として保存するソースコードを紹介します。
This procedure will create GIF image of chart to selected folder.
- Comments: 0
- TrackBack (Close): 0
GraphConrol Ver.201 English Version(英語バージョン) Distribution
- 2008年5月13日 09:05
- Excel Graph | Excel VBA | GraphControl
Introducing English version of a little Excel software 'GraphControl'. This software will help your Excel work, and save your time.
Download GraphControl_en Ver.203
- Ajust height of width of charts(if "ALL" is checked, then all chart will be ajusted)
- Change color of chartarea, plotarea, wall(3D), floor(3D) by using Excel est. Textures, gradation, and 56 color-index
- Change to rounded or square corner, or shadow graph.
- Change Rotation, Elevation etc. of 3D graph.
- Create graph image(GIF) to selected folder
- Reverse graph both X and Y axis
- Change color and style of marker in line graph
- And so on...
I would like to refer and speak to freedom on this little Excel software "GraphControl". I offer you this license which gives you legal permission to copy, distribute and/or modify the software. It is complete open source, and I am very welcome you to modify and develop "GraphControl" to better software to distribute. You can change the link label on UserForm to your website only if you can support end users. Also, for each author's protection and ours, I want to make certain that everyone understands that there is no warranty for this software. Arg. We do not need "Tower of Babel" in the world of computer, don't we?
- Comments: 0
- TrackBack (Close): 0
GraphConrol Ver.201 配布開始
- 2008年5月11日 21:38
- Excel Graph | Excel VBA | GraphControl
GraphConrol Ver. 201 GraphConrol Ver. 202を配布開始します。新機能を追加しています。
- グラフを指定フォルダに GIF画像として保存できるようにしました。
- ツールバーのメニューに追加しました。
- 複数のブックを開いていても、ブック、シート、グラフを指定することが出来ます。
使い方は、グラフコントロール画面のコンボボックスで開いているブックを選択してボタンを押すと指定されたブックがアクティブになります(後から開いたブックは読み込みません)。オプションとして、カスケードスタイルやタイルスタイルなどを選択して表示出来るようにしました。
グラフ画像作成ボタンでは、選択したグラフをコンボボックスで指定したフォルダに保存します。フォルダがないと保存出来ませんので、前もってフォルダを作成しておいてください。「全部」のグラフが指定されている場合は、シート上の全グラフ画像が作成されます(画像はGIF形式です)。保存されるグラフ画像の名前は、グラフタイトルです。もしタイトルがなかったら、ブック名(上のコンボボックスが空欄の場合はなし) + _グラフ番号で保存されます
ダウンロードは↓です。
DownLoad GraphControl Ver.203
- Comments: 0
- TrackBack (Close): 0
CombSort11 Function & Procedure for VBA (コムソートで配列を並び替える)
今回のソート・アルゴリズムはCombSort と呼ばれるものです。これも、N * Log N の計算量です。エクセルVBAで、1,000,000 の数値の配列を20数秒で並び替えます。ヒープソート(Heapsort)も、アルゴリズムの理論値が同じですから、ほぼ同じような結果になります。N²のアルゴリズムのソート方法では、10,000の並び替えに同じくらいの時間がかかりました。その方法で、1,000,000 の数値配列の並び替えは無理かもしれません(実験しようとも思いません)。アルゴリズムを構築する者があまりハードウェアの分野に入り込まない方がいいかもしれません。
This sorting algorithm is called CombSort. The quantity of calculation is also N*LogN,and the array of the numerical value of 1,000,000 is sorted in about twenty seconds by Excel VBA. Heapsort also brings the almost same result, because of same theoretical value of an algorithm. By the sorting algorithm of N², sorting of 10,000 took about the same time. So that, by that method, sorting of the numerical array of 1,000,000 may be unreasonable. I think those who build an algorithm had better not seldom enter into the field of hardware.
- Comments: 0
- TrackBack (Close): 0
HeapSort Function & Procedure For VBA(ヒープソートアルゴリズム)
ヒープソート(Heap Sort)のVBAコードを紹介します。クイックソート(Quick Sort) をVBAで使うとエラーが発生するので、長い配列の並び替えをする場合にこのコードがあるととても重宝すると思います。N² の原始的なソート方法とは比較にならないほど早いです。
Quick Sort Algorithm (クイックソート)
ソートのアルゴリズムについて: ソートのアルゴリズムの計算量は、分かりやすいように大きく2つに分類すると、N²とN*Log N に分けられます。アルゴリズムを構築する場合、この "N" はとても大きな数値だと仮定しなければいけません。下のテーブルのように、計算量がN² の 1/100 となったとしてもアルゴリズム上の理論値は N²です。
The VBA code of heap sort is end of this article. I think that it is found useful very much if there is this code when sorting long array, because an error will occur if quick sort is used by VBA. It is so fast that it cannot be compared with the primitive method.
| Algorithm | Example |
|---|---|
| N²= | N² * 1/3 N² * 1/10 N² * 1/100 |
| N*Log N= | N*Log N * 2 N*Log N * 10 N*Log N * 100 |
下のコードはに、3つの N² のアルゴリズムのソートです。1つ目のソートは、順番に小さい数値を見つけて挿入していくソートです。このソートは、N² * 1/2 の計算量です。2つ目は、最初と最後を比較していくソートで、3つ目は一番小さい数値と大きな数値を見つけて挿入するソートです。このソートは、N² * 1/4 の計算量です。4つ目は、一番小さい数値と大きな数値を2つ見つけて挿入するソートです。計算量は、N² * 1/6 になります。膨大な量のデータをこういった原始的なアルゴリズムで並び替えようとすると大変なことになります。
These are 4 samples of primitive method which takes quantity of calculation N².
下のリンクに続きます。
- Comments: 0
- TrackBack (Close): 0
QuickSort Function & Procedure For VBA(クイックソートアルゴリズム)
先日書いたクイックソートの記事で少し勘違いしてた部分がありましたので書き換えました。今回は、Procedure と Function の両方のコードを紹介します。ExcelVBAのレベルでは、今のところこういったソートを個人レベルで利用することはあまり必要ではありませんが、多くの人が使うアドインなどに組み込む場合は必要です。クイックソートの他にヒープソート(Heap Sort)と呼ばれる(これも計算量:N*Log N)で安定したソート方法がありますので次の記事で紹介します。
QuickSort のアルゴリズムを用いたVBA 用のコードを紹介します。このアルゴリズムは配列に適しています。クイックソートはある条件下において、効率が悪くなることがあります。このアルゴリズムは、比較するためのPivotを配列の中心の値にしてますが、本来のPivot の位置は配列の先頭の値です。この場合だと、降順を昇順に、または昇順を降順にソートする場合に処理量がN²となってしまいます。Pivotの位置を変えても、一定の条件下では効率が悪くなることがあります。イントロソートと呼ばれるソート方法がありますが、これはクイックソートの効率が悪くなる条件の場合、ヒープソートに切り替えるものです。
しかし、平均的に、N*Log N の処理量を実現してますので、とても優秀なアルゴリズムです。しかしながら、エクセルVBA のレベルでは、配列が大きくなったとき、「スタック領域・・・」とエラーが出て、あまり使えそうにありません。長い配列を使う場合はヒープソートを使うといいと思います。本来は、本当に処理速度を追求するのであれば、配列なんて便利なものは使えません。便利なものは必ず何かを犠牲にします。
クイックソートが作られた時代に配列などはなく、データ構造はレコードをポインターで繋いだ構造でした。ポインターを使うことでとても自由なプログラミングが可能になりますが、一度ポインターが切れるとデータは2度と捕まえることが出来ません。その環境で書かれたプログラムは、アルゴリズムが完成してないと、厄介なプログラムになってしまいます。 20年前に、ポインターをネットワーク状に張り巡らせたソートプログラムを作りました。少しだけメモリを使いますが、安定したプログラムでした。機会があったら紹介したいと思います。
I rewrote this article, since there was a portion which misunderstood with the article of quick sort written the other day. Although it is not so much required on the level of ExcelVBA to use such sorting on an individual level for the moment. It is called the "Heap Sort" other than quick sort which is the stable sorting method, it introduces with the following article.
This is code of QuickSort Function & Procedure which is written in VBA. This algorithm is suitable for sorting array. Since quick sort has realized the amount of processings of N*Log N, it is a very excellent algorithm on the average, also sometimes its efficiency may worsen under a certain condition. Although this algorithm makes Pivot for comparing the value of the center of arrangement, the position of original Pivot is a value of the head of arrangement. The amount of processings will be N² if quicksort sort an ascending order to descending order. Even if it changes the position of Pivot, efficiency may worsen under certain conditions. Although there is the sorting method called "intro sort". this method will change to a heap sort, when the efficiency of quick sort is the worsening conditions. if processing speed is pursued truly, a convenient thing cannot be used. convenience sometimes sacrifice something.
I was writing Pascal. It's very free programming is attained by using a pointer. The program written in the environment will turn into a troublesome program, if the algorithm is not completed. 20 years ago, I have made the sorting program which spread the pointers around in the shape of a network. it was the more stabilized program than quick sort. I want to introduce, when there is an opportunity.
- Comments: 0
- TrackBack (Close): 0
Excel で生まれてからの日数&干支を求めるマクロ(
- 2008年4月29日 13:23
- Excel VBA | Useful Technic
生まれてからの、日数と週数、そして干支を求めるマクロです。
This sample code find out number of days&week from your birth.
- Comments: 0
- TrackBack (Close): 0
エクセル データ変換関数(Excel Function to convert data)
20年前(1980年代)の初期のPascal言語では、今のようなStringやVariantなどの変数がなかったので、文字列を読み込む際は、1文字ずつループで読み込みをしていました。変数CharでスペースやIntegerを読み込もうとするとエラーとなり、条件を指定してから読み込むコードを書いていました。Turbo Pascalがパソコン用のソフトで出てきたころからStringが認識できるようになりました。
Excel では、セル値などの(.Value)の付いているものはほとんどがVariant型です(Spinbutton.Value=Long などの例外もあります)。エクセルの数式で、
Range("A1").Value+Range("B1").Value
などと、セル値同士を計算させることも出来ます。しかしVariant型同士の計算式はエクセルが自動で処理してくれているだけで、これはエラーの原因にもなります。簡単な処理であれば問題はないでしょうが、大量の計算処理をした場合は何の保証もありません。PascalであれExcelであれ、扱っているデータタイプをしっかりと区別してから処理させることは基本であり、とても重要なことです。
20 years ago (the second half of the 1980s), I have leaned Pascal language. In Pascal at that time, since there were no variables, such as present String and Variant, when reading a character string, it was reading one character at a time by the loop. The code read after specifying conditions to prevent error. When Turbo Pascal came out with the software for personal computers, Pacal could recognize Var String.
In Excel, most of variables, such as a cell value are Variant type (there is also an exception of Spinbutton.Value=Long etc.). Cell values can also be made to calculate with Range("A1").Value+Range("B1").Value etc. with the expression of Excel. However, this formula is calculated automatically by Excel. While it is in easy processing, it will not cause error. But when a lot of calculation processing is carried out, there is no guarantee. Whether if Pascal, Excel or other language, it is foundations to make it to process, after distinguishing the data type, and it is very important.
| VBA Function | Data Conversion | Example |
|---|---|---|
| CInt(Expression) | Integer型に変換 Convert Numeric to Integer |
CInt("32767")=32767 CInt("32768")=Error(オーバーフロー) CInt("-32768")=-32768 CInt("-32769")=Error(オーバーフロー) |
| CLng(Expression) | Long型に変換 Convert Numeric to Long |
CLng("100")=100 -2,147,483,648~2,147,483,647の範囲(4Byte) CLng("2,147,483,648")=Error(オーバーフロー) |
| CSng(Expression) | Single型に変換 Convert Numeric to Single |
CSng("0.123456")=0.123456 1.401298E-45 ~ 3.402823E38(プラス値) -3.402823E38 ~ -1.401298E-45(マイナス値) CSng("3.402824E38")=Error(オーバーフロー) CSng(1.401298E-46)=0 |
| CDbl(Expression) | Double型に変換 Convert String or Numeric to Double |
4.94065645841247E-324 ~ 1.79769313486231E+308(プラス値) -1.79769313486231E308 ~ -4.94065645841247E-324(マイナス値) CDbl("1.79769313486232E308")=>オーバーフロー CDbl("1.79769313486231E308")=1.79769313486231E+308 |
| CBool(Expression) | Boolean型に変換 Convert String or Numeric to Boolean |
CBool(0)=FALSE CBool(0以外の数値)=TRUE CBool(0.1)=TRUE CBool(CInt(0.1))=FALSE CBool("String")=Error(型が一致しない) CBool("TRUE")=TRUE CBool("0")=FALSE CBool("2")=TRUE |
| CStr(Expression) | String型に変換 Convert to String |
CStr(10)="10" CStr(CSng("3.402823E38"))="3.402823E+38" CStr(CSng("3.402824E38"))=Error(文字列変換の前にオーバーフロー) |
| CVar(Expression) | Variant型に変換 Convert to Variant |
CVar(CStr(10) * CInt(19))=190 CVar(CStr(10) & CInt(19))=1019 特殊な関数で、使い方次第でエラーの原因になる可能性があります。 |
| CDec(Expression) | 10進数型(Decimal)に変換 Convert String or Numeric to Decimal |
CDec("1")=1 CDec("String")=Error(型が一致しない) VBの計算は2進数が基準のため、精密な計算をする際に 少数点以下の誤差(以下の例)をなくすために使う CDec(CSng(1.2345E-12))=0.00000012345 CSng(1.2345E-12)=0.00000012345000239 |
| CByte(Expression) | Byte型に変換 Convert String or Numeric to Byte |
CByte("1")=1 CByte(255)=255 CByte(-0.5)=0 CByte(256)=Error(オーバーフロー) CByte(-5.01)=Error(オーバーフロー) |
| CDate(Expression) | Date型に変換 Convert String or Numeric to Date |
CDate("平成20年4月29日")=2008/04/29 CDate("1")=1899/12/31 CDate(2)=1900/01/01 CDate(0)=0:00:00 CDate("10000")=1927/05/18 |
| Hex(Expression) | 16進数に変換 Convert to Hexadecimal |
Hex("&h5a")=5A Hex("&08")=Error Hex(1000)=3E8 CLng(Hex(1000))=300000000 (Notes:"3E8"→"3E+8") |
| Val(Expression) | 文字列を数値に変換 Convert String to Numeric |
Val("1000")=1000 Val(1)=1 Val("1.23")=1.23 Val("1 0,12")=10 (スペースや"コンマなどのキャラクター文字以下"は無視される) Val("全角")=0 |
- Comments: 0
- TrackBack (Close): 0
Excel Spinbutton のイベントの活用(Spinbutton SpinDown SpinUp event)
- 2008年4月28日 06:20
- Excel VBA | Useful Technic
前の記事で、スピンボタンを使ってスクロールする方法の記事を書きましたが、スピンボタンのイベントでSpinbutton_Change() 以外のイベント(SpinDown & SpinUp イベント)を使用する方法を紹介します。プロシージャは2つに増えてコマンドボタンを使うのと同じような感じになります。
Spinbutton_Change() で操作する方法
using SpinDown event & SpinUp event instead of Spinbutton_change().
- Comments: 0
- TrackBack (Close): 0
Excel ブックをウィンドウアレンジで表示方法を変える(XlArrangeStyle)
- 2008年4月27日 07:44
- Excel VBA | Useful Technic
エクセルの複数開いているブックの表示をアレンジして変えるコードです。
How to arrange windows of Excel books.
| スタイル | Style | Class menber |
|---|---|---|
| カスケードスタイル | StyleCascade | xlArrangeStyleCascade |
| タイリングスタイル | StyleTiled | xlArrangeStyleTiled |
| 横並びスタイル | StyleHorizontal | xlArrangeStyleHorizontal |
| 縦並びスタイル | StyleVertical | xlArrangeStyleVertical |
xlArrangeStyleVertical
xlArrangeStyleCascade
xlArrangeStyleHorizontal
- Comments: 0
- TrackBack (Close): 0
Excel グラフの名前を番号にするマクロ(Rearranging Name of Excel Charts as specified)
- 2008年4月26日 10:43
- Excel VBA | Useful Technic
前回にシートの並び替えに引き続き、今回はグラフに番号の名前をつけるマクロを紹介します
How to change name of chart to specific number.
- Comments: 0
- TrackBack (Close): 0
Excel シートを順番に並び替えるマクロ(Rearranging Excel Sheets in order)
- 2008年4月26日 08:17
- Excel VBA | Useful Technic
- Comments: 0
- TrackBack (Close): 0
Excel グラフの目盛り線を消す(Delete Gridlines of chart. xlValue xlCategory)
- 2008年4月26日 07:58
- Excel VBA | GraphControl
- Comments: 0
- TrackBack (Close): 0
Excel グラフの高さ&幅をスピンボタンで設定(Change Height & Width of Excel Chart by Spinbutton)
- 2008年4月25日 07:40
- Excel VBA | Useful Technic
スピンボタンを使って、グラフの高さ(幅)などを設定する簡単なアルゴリズムを紹介します。
Easy algorithm to change Excel Chart Setting by spinbutton.
下記のページは、Spindown & SpinUp イベントを使用した例です。プロシージャが2つになりますので、コマンドボタンを使った時とほぼ同じようになります。
Spinbutton_spindown & spinup event
Continue reading
- Comments: 0
- TrackBack (Close): 0
Excel グラフの高さ&幅設定(ChartObjects .Height & Width)
- 2008年4月25日 07:03
- Excel VBA | GraphControl
エクセルグラフの高さと幅を設定うするマクロを紹介します。
- Comments: 0
- TrackBack (Close): 0
Excel グラフのパターン色 (.Fill.Patterned Pattern)
- 2008年4月24日 08:16
- Excel VBA | GraphControl
エクセルグラフをパターン色にする。
| 名前 | Name | .Fill.Patterned Pattern:= |
|---|---|---|
| 5% | 5Percent | msoPattern5Percent |
| 10% | 10Percent | msoPattern10Percent |
| 20% | 20Percent | msoPattern20Percent |
| 25% | 25Percent | msoPattern25Percent |
| 30% | 30Percent | msoPattern30Percent |
| 40% | 40Percent | msoPattern40Percent |
| 50% | 50Percent | msoPattern50Percent |
| 60% | 60Percent | msoPattern60Percent |
| 70% | 70Percent | msoPattern70Percent |
| 75% | 75Percent | msoPattern75Percent |
| 80% | 80Percent | msoPattern80Percent |
| 90% | 90Percent | msoPattern90Percent |
| うろこ | Shingle | msoPatternShingle |
| ざらざら | Trellis | msoPatternTrellis |
| ひし形_強調 | SolidDiamond | msoPatternSolidDiamond |
| ひし形_点 | DottedDiamond | msoPatternDottedDiamond |
| ひし形_枠のみ | OutlinedDiamond | msoPatternOutlinedDiamond |
| れんが_横 | HorizontalBrick | msoPatternHorizontalBrick |
| れんが_斜め | DiagonalBrick | msoPatternDiagonalBrick |
| 右下がり対角線_太 | WideDownwardDiagonal | msoPatternWideDownwardDiagonal |
| 右下がり対角線_破線 | DashedDownwardDiagonal | msoPatternDashedDownwardDiagonal |
| 右下がり対角線_反転 | DarkDownwardDiagonal | msoPatternDarkDownwardDiagonal |
| 右下がり対角線 | DownwardDiagonal | msoPatternLightDownwardDiagonal |
| 右上がり対角線_太 | WideUpwardDiagonal | msoPatternWideUpwardDiagonal |
| 右上がり対角線_破線 | DashedUpwardDiagonal | msoPatternDashedUpwardDiagonal |
| 右上がり対角線_反転 | DarkUpwardDiagonal | msoPatternDarkUpwardDiagonal |
| 右上がり対角線 | UpwardDiagonal | msoPatternLightUpwardDiagonal |
| 横線_太 | DarkHorizontal | msoPatternDarkHorizontal |
| 横線_破線 | DashedHorizontal | msoPatternDashedHorizontal |
| 横線_反転 | NarrowHorizontal | msoPatternNarrowHorizontal |
| 横線 | Horizontal | msoPatternLightHorizontal |
| 格子_小 | SmallGrid | msoPatternSmallGrid |
| 格子_大 | LargeGrid | msoPatternLargeGrid |
| 格子_点 | DottedGrid | msoPatternDottedGrid |
| 球 | Sphere | msoPatternSphere |
| 市松模様_小 | SmallCheckerBoard | msoPatternSmallCheckerBoard |
| 市松模様_大 | LargeCheckerBoard | msoPatternLargeCheckerBoard |
| 紙ふぶき_小 | SmallConfetti | msoPatternSmallConfetti |
| 紙ふぶき_大 | LargeConfetti | msoPatternLargeConfetti |
| 縦線_太 | DarkVertical | msoPatternDarkVertical |
| 縦線_破線 | DashedVertical | msoPatternDashedVertical |
| 縦線_反転 | NarrowVertical | msoPatternNarrowVertical |
| 縦線 | Vertical | msoPatternLightVertical |
| 小波 | Wave | msoPatternWave |
| 大波 | ZigZag | msoPatternZigZag |
| 切り込み | Divot | msoPatternDivot |
| 編み込み | Plaid | msoPatternPlaid |
| 網目 | Weave | msoPatternWeave |
- Comments: 0
- TrackBack (Close): 0
Excel グラフのマーカーの種類(MarkerStyle)
- 2008年4月24日 07:40
- Excel VBA | GraphControl
MarkerStyle (マーカーの種類)
エクセル既定のマーカーの種類です(9種類)。系列1を選択する場合は、ActiveChart.SeriesCollection(1).Select となります。サイズは2~72までです。
| マーカー | Excel Fixed | Code |
|---|---|---|
| ○ | xlCircle | Selection.MarkerStyle = xlCircle |
| □ | xlSquare | Selection.MarkerStyle = xlSquare |
| ♢ | xlDiamond | Selection.MarkerStyle = xlDiamond |
| △ | xlTriangle | Selection.MarkerStyle = xlTriangle |
| ☆ | xlStar | Selection.MarkerStyle = xlStar/td> |
| + | xlPlus | Selection.MarkerStyle = xlPlus |
| ― | xlDash | Selection.MarkerStyle = xlDash |
| - | xlDot | Selection.MarkerStyle = xlDot |
| X | xlX | Selection.MarkerStyle = xlX |
| なし | xlNone | Selection.MarkerStyle = xlNone |
| サイズ | Size | Code |
| 2~72 | From 2 to 72 | Selection.MarkerSize = 5 (default) |
- Comments: 0
- TrackBack (Close): 0
Excel グラフの目盛り線を設定(MajorGridlines Border LineStyle Axes(xlCategory) )
- 2008年4月24日 06:30
- Excel VBA | GraphControl
- Comments: 0
- TrackBack (Close): 0
Excel 3Dグラフの回転設定(3D Chart Rotaion)
- 2008年4月23日 07:56
- Excel VBA | GraphControl
エクセル3Dグラフの回転の値を設定する。
setting up ActiveChart.Rotation of Excel chart.
訂正のお知らせ:3Dグラフの回転を設定するコードに誤りがありました。 Rotation = ActiveChart.Rotationの部分が Rotation = ActiveChart.Elevationとなっていました。訂正と改善した部分がありましたのでお知らせします。
- Comments: 0
- TrackBack (Close): 0
ルーレットシステムシミュレーション Roulette System Simulation
このプログラムは、株などのシステムトレードのように、ルーレットシステムが成立するかどうかを簡単に検証するものです。答えは、このページで説明しているようにほぼ100%不可能です。
画像は、仮想ルーレットデータを10,000回の乱数を発生させて以下を検証したものです。
- ルーレットがRed,Red, Evenと続いたとき、Redに5%
- ルーレットがRed,Red, Even, Even, Blackと続いたとき、Odd(奇数)に15%
- ルーレットがRed,Red, Even, Even, Black, Black,Oddと続いたとき、Blackに25%
結果は、図の例のように時々プラスに転じる場合があります。
This program verifies whether you can build a Roulette System like trading system of Stock market. The answer is, almost 100% impossible because distortion of odds has no trend. For example, if you repeat trading in stock market when stock price does not change, you'll never make anything.
Image is verification of 10,000 times virtual roulette data according to probability below.
- Bet 5% of funds to "Red" when roulette become as Red,Red,Even.
- Bet 15% of funds to "Odd" when roulette become as Red,Red,Even,Even,Black.
- Bet 25% of funds to "Black" when roulette become as Red,Red,Even,Even,Black,Black,Odd.
As a result in this case, become 650000 profit. Sometime it's happened. We call it "luck". Chart of profit and loss curve is below.
Download is under preparation
Download Roulette System Simulation
損益曲線は以下のとおりです。
- Comments: 0
- TrackBack (Close): 0
Excel グラフをテキスチャに設定する Texture of ground colors(PresetTextured)
- 2008年4月22日 08:21
- Excel VBA | GraphControl
エクセルグラフを既定のテキスチャに設定するマクロです。
Set up Excel chart by texture of ground colors which is fixed in Excel.
| テキスチャの名前 | Name of Texture | PresetTextured | Number |
|---|---|---|---|
| 紙 | Papyrus | msoTexturePapyrus | 1 |
| キャンバス | Canvas | msoTextureCanvas | 2 |
| デニム | Denim | msoTextureDenim | 3 |
| 麻 | WovenMat | msoTextureWovenMat | 4 |
| しずく | WaterDroplets | msoTextureWaterDroplets | 5 |
| 紙袋 | PaperBag | msoTexturePaperBag | 6 |
| 化石 | FishFossil | msoTextureFishFossil | 7 |
| 砂 | Sand | msoTextureSand | 8 |
| 大理石(緑) | GreenMarble | msoTextureGreenMarble | 9 |
| 大理石(白) | WhiteMarble | msoTextureWhiteMarble | 10 |
| 大理石(茶) | BrownMarble | msoTextureBrownMarble | 11 |
| みかげ石 | Granite | msoTextureGranite | 12 |
| 新聞紙 | Newsprint | msoTextureNewsprint | 13 |
| 再生紙 | RecycledPaper | msoTextureRecycledPaper | 14 |
| セーム皮 | Parchment | msoTextureParchment | 15 |
| ひな形 | Stationery | msoTextureStationery | 16 |
| 青い画用紙 | BlueTissuePaper | msoTextureBlueTissuePaper | 17 |
| ピンクの画用紙 | PinkTissuePaper | msoTexturePinkTissuePaper | 18 |
| 紫のメッシュ | PurpleMesh | msoTexturePurpleMesh | 19 |
| ブーケ | Bouquet | msoTextureBouquet | 20 |
| コルク | Cork | msoTextureCork | 21 |
| くるみ | Walnut | msoTextureWalnut | 22 |
| オーク | Oak | msoTextureOak | 23 |
| 木目 | MediumWood | msoTextureMediumWood | 24 |
- Comments: 0
- TrackBack (Close): 0
Excel グラフを透明にする Transparent (.Interior.ColorIndex)
- 2008年4月22日 07:40
- Excel VBA | GraphControl
- Comments: 0
- TrackBack (Close): 0
Excel グラフ 既定のグラデーション (.PresetGradient Style, Type, Variant)
- 2008年4月21日 06:48
- Excel VBA | GraphControl
エクセルグラフのプロットエリア、チャートエリア、壁面、床面を既定のグラデーションに設定するマクロを紹介します。以下は、エクセル既定のグラデーションの種類とタイプです。
The following table indicates the est. color in Excel.
| グラデーションの種類 | Name of Gradation | GradientType |
|---|---|---|
| 夕焼け | EarlySunset | msoGradientEarlySunset |
| 日暮れ | LateSunset | msoGradientLateSunset |
| 夕闇 | Nightfall | msoGradientNightfall |
| 夜明け | Daybreak | msoGradientDaybreak |
| 地平線 | Horizon | msoGradientHorizon |
| 砂漠 | Desert | msoGradientDesert |
| 海 | Ocean | msoGradientOcean |
| 凪 | CalmWater | msoGradientCalmWater |
| 炎 | Fire | msoGradientFire |
| 霧 | Fog | msoGradientFog |
| こけ | Moss | msoGradientMoss |
| くじゃく | Peacock | msoGradientPeacock |
| 小麦 | Wheat | msoGradientWheat |
| セーム皮 | Parchment | msoGradientParchment |
| マホガニー | Mahogany | msoGradientMahogany |
| 虹 | Rainbow | msoGradientRainbow |
| 虹2 | RainbowII | msoGradientRainbowII |
| ゴールド | Gold | msoGradientGold |
| ゴールド2 | GoldII | msoGradientGoldII |
| ブロンズ | Brass | msoGradientBrass |
| クロム | Chrome | msoGradientChrome |
| クロム2 | ChromeII | msoGradientChromeII |
| シルバー | Silver | msoGradientSilver |
| サファイア | Sapphire | msoGradientSapphire |
| グラデーションのスタイル | Style of Gradation | Gradient Style |
|---|---|---|
| 横 | Horizontal | msoGradientHorizontal |
| 縦 | Vertical | msoGradientVertical |
| 右上対角線 | Diagonal Up | msoGradientDiagonalUp |
| 右下対角線 | Diagonal Down | msoGradientDiagonalDown |
| 角から | From Corner | msoGradientFromCorner |
| 中央から | From Center | msoGradientFromCenter |
- Comments: 0
- TrackBack (Close): 0
Excel グラフを単一色に変える(.PlotArea .ChartArea .Walls .Floor)
- 2008年4月20日 06:47
- Excel VBA | GraphControl
エクセルチャートの色を単一色に変えるソースコードです。
At this article, introducing some source codes to change graph into a single color.
- Comments: 0
- TrackBack (Close): 0
Excel グラフを動かす move chart on Excel sheet (.top)
- 2008年4月19日 07:08
- Excel VBA | GraphControl
エクセルのシート上のグラフをユーザーフォームなどで動かすためのコードを紹介します。
At this article, introducing source codes to move charts on Excel sheet by commandbutton.
- Comments: 0
- TrackBack (Close): 0
Excel 株価チャートの陽線&陰線の色を変える(UpBars & DownBars of stock chart)
- 2008年4月18日 08:32
- Excel VBA | GraphControl
株価チャートの陽線と陰線(ローソク足)の色を設定するサンプルコードを紹介します。
I have added to an option to GraphControl that is for stock chart. It's able to change color of candle bars that is shown in stock chart.
- Comments: 0
- TrackBack (Close): 0
Excel グラフの系列を設定する(Interior, LineStyle, border color)
- 2008年4月17日 16:53
- Excel VBA | GraphControl
エクセルグラフの系列のインテリア、ボーダー、線の色、マーカータイプと大きさなどを設定するソースコードを紹介します。
At this time, introducing some codes to set up seriesCollection. it will be the LineStyle, Maker style, color etc.
- Comments: 0
- TrackBack (Close): 0
Excel 3Dグラフの奥行設定(3D Chart Perspective)
- 2008年4月17日 08:49
- Excel VBA | GraphControl
エクセル3Dグラフの奥行きを設定するマクロを紹介します。
Excel VBA source code which set the value perspective of 3D Chart.
- Comments: 0
- TrackBack (Close): 0
UserFormからシートをスクロール(Scrolling spread sheet from userform)
- 2008年4月17日 07:16
- Excel VBA | GraphControl
UserForm からエクセルシートをスクロールさせるマクロです。
Scrolling Excel's spead sheet using spinbtton.
- Comments: 0
- TrackBack (Close): 0
Excel 3Dグラフの高さ設定(3D Chart Height percentage)
- 2008年4月15日 08:29
- Excel VBA | GraphControl
エクセル3DグラフのX軸高さの比率を設定するマクロを紹介します。
introducing the excel's source code of setting the 3D chart (.HeightPercent).
- Comments: 0
- TrackBack (Close): 0
Excel 3Dグラフの仰角設定(3D Chart Elevation)
- 2008年4月15日 07:06
- Excel VBA | GraphControl
エクセルの3Dグラフの仰角を調整するマクロを紹介します。
- Comments: 0
- TrackBack (Close): 0
Excel グラフに影を付けるマクロ(.Shadow)
- 2008年4月14日 17:14
- Excel VBA | GraphControl
エクセルのグラフに影をつけるソースコードを紹介します。
This source code is to create shadow background of the selected chart.
- Comments: 0
- TrackBack (Close): 0
Excel グラフのコーナーを丸くするマクロ(.RoundedCorners)
- 2008年4月14日 08:53
- Excel VBA | GraphControl
- Comments: 0
- TrackBack (Close): 0
Excel グラフを反転させるマクロ(ソースコード)Axes(xlCategory)
- 2008年4月13日 14:51
- Excel VBA | GraphControl
前回は、数値軸(Y軸)の反転させるコードを紹介しました。今回は、項目軸(X軸)の反転をするコードです。
At this time, introducing a code to reverse xlCategory of selected chartobject.
- Comments: 0
- TrackBack (Close): 0
Excel グラフを反転させるマクロ(ソースコード)Axes(xlValue)
- 2008年4月13日 13:40
- Excel VBA | GraphControl
エクセルグラフのX軸、Y軸(第1軸、第2軸)を反転するエクセルマクロのソースコードを紹介します。
実行されると、チャートの数値軸(Y軸)を反転します。もし上下反転していれば、元に戻ります。
The code reverses selected graph upside down. Procedure carry out both Axes(xlValue, xlPrimary) and Axes(xlValue,xlSecondary). If the selected chart is already reverse order then will put it back.
- Comments: 0
- TrackBack (Close): 0
Home > Excel VBA Archive
Search