5

最小値、最大値、現在値の 3 つの値を持つダッシュボード プロジェクトに取り組んでいます。最小値と最大値はバーのエンドポイントになり、バーに沿った適切な位置に現在の値を含むテキスト ボックスを配置したいと思います。下記参照:

Excelでこれを行うことは可能ですか?可能であれば、どうすればこれを達成できますか. Visual Basic の使用経験はありますが、これに出会ったことはありません。

ここに画像の説明を入力

最終的に、次のリンクでダッシュボードの Excel バージョンを実行しようとしています。

ダッシュボードへのリンク

4

3 に答える 3

3

Shape-objectが選択されていないときにマクロ記録をオンにします。次にそれを選択し、その位置を変更します。記録を停止し、生成されたコードを使用します。

私がそれを試したとき、それは私にとって有用に見えます。IncrementTopとIncrementLeftのコードを取得しました。TopプロパティとLeftプロパティを直接使用することもできます。

コードを読みやすくするために、Shapeオブジェクトの名前を意味のある名前(数式ボックスの左側にあるアドレスボックス内)に変更することをお勧めします。

したがって、PositionIndicatorという名前のShapeの場合:

ActiveSheet.Shapes("PositionIndicator").Left = 250

または

ActiveSheet.Shapes("PositionIndicator").Left = _ 
    ActiveSheet.Shapes("PositionIndicator").Left + 5

セル値にリンクするには、次を使用しますRange("CELLADDRESS").Value2

セルの値を変更するたびに適用するには、次を使用します。

Private Sub Worksheet_Change(ByVal Target As Range)
    'Here your script to check if the change concerns one of your input cells and then run the code to change the location of the Shape-object
End Sub

幸運を

于 2013-03-19T13:58:45.920 に答える
1

私はあなたのアイデアが好きなので、完全なコードがどのように見えるかを確認しました。結果は次のとおりです。

Sub SolutionShape(currentVal)

Dim shpBar As Shape, shpCurrent As Shape

'let's assume we have only two shapes on the Activesheet
Set shpBar = ActiveSheet.Shapes(1)
Set shpCurrent = ActiveSheet.Shapes(2)

Dim barMin As Double, barMax As Double
    barMin = 0.51              'both values could be taken from sheet
    barMax = 6.75

'let's do it visualy complicated this time :)
With shpCurrent
    .Left = (-.Width / 2 + shpBar.Left) + _
        (((currentVal - barMin) / (barMax - barMin)) * shpBar.Width)

    **'EDITED- adding information about current value:**
    .TextFrame.Characters.Text = currentVal
End With

End Sub

テスト用の即時ウィンドウからのイベントからプロシージャを呼び出します。

SolutionShape 0.51      'go to beginning
SolutionShape 6.75      'go to end

このソリューションは、形状を配置する場所や、設定した形状の新しい寸法に関係なく機能します。

于 2013-03-19T14:11:38.430 に答える
1

プログレス バーがワークシート上の図形 (インデックス 1) であり、テキスト ボックスが図形インデックス 2 であると仮定します。以下は、完了率に基づいてプログレスバーに沿ってテキストボックスを移動します。

注: 矢印の頭の左側にあるテキスト ボックスの形状の部分をオフセットするように調整する必要があります。

Option Explicit
Public Sub movebox()

    Dim textbox As Shape, progbar As Shape
    Dim ws As Worksheet
    Dim stp As Integer, endp As Integer
    Dim tbdyn As Integer
    Dim mn As Double, mx As Double, actper As Double, cur As Double
    Dim admn As Double, admx As Double

    Set ws = Sheets("sheet1")
    Set progbar = ws.Shapes(1)
    Set textbox = ws.Shapes(2)

'// Far left of progress bar position
    stp = progbar.Left
'// Far right of progress bar position
    endp = (progbar.Width + stp)

'// Adjust for starting at 0.51
'// You could adjust mn,mx and cur to take the values
'// from the appropriate cells on the spreadsheet
    mn = 0.51
    mx = 6.07
    admn = 0
    admx = 6.07 - mn
    cur = 4
'// Calculate percentage complete
    actper = cur / admx
'// Apply percentage to progress bar
    tbdyn = actper * endp
'// Move the textox appropriately
    textbox.Left = tbdyn

End Sub
于 2013-03-19T14:13:59.070 に答える