Home > Excel VBA | GraphControl > Excel グラフを動かす move chart on Excel sheet (.top)

Excel グラフを動かす move chart on Excel sheet (.top)


エクセルのシート上のグラフをユーザーフォームなどで動かすためのコードを紹介します。

At this article, introducing source codes to move charts on Excel sheet by commandbutton.

エクセルのシート上のグラフを移動させるソースコードを紹介します。CH1t に現在のグラフの上からの距離(.Top)の値を代入して、上げたいだけ(ここでは20に設定)値から引いて .Top を設定します。下の行はグラフが他のグラフの下に隠れている場合に見えるようにします。

   ActiveSheet.ChartObjects(1).Activate

The Excel VBA source code below is to move up ChartObjects(1) by 20. Declare var CH1t as single, and then substitute a current value of "ChartObject(1).Top", decrease 20 from CH1t.

above is in the line 13. You donot need this line unless there're a bunch of charts on the sheet. Graph may hide, you know. I added the line below to prevent error.

If ActiveSheet.ChartObjects.Count = 0 Then Exit Sub

GraphControl で使用しているコードです。コマンドボタンを使用してます。スピンボタンでも出来ます。スピンボタンを使用した例は、シートをスクロールするコードで説明しています。グラフを動かすコードの場合は、シートに値を書き込むか配列などのメモリに値を格納するとシートをスクロールするコードの例のように2度プロシージャを呼び出さずに出来ます。

the code below is used in GraphControl. I adopted commandbutton, however it is also possible to spinbutton. If you want to use spinbutton in this case, you should substitute values to variable that may be array or cells in particular sheet etc. I donot recommend this example to use spinbutton in this case.

Comments:0

Comment Form

Home > Excel VBA | GraphControl > Excel グラフを動かす move chart on Excel sheet (.top)

Return to page top