2016-12-30 4 views
0

範囲の条件付き書式設定をdatabarで追加するVBAスクリプトを作成しようとしています。私は下のコードを書いていますが、databarの色をどのように変更するのか分かりませんし、異なる境界を提供しています。データバーオブジェクトの書式設定

奇妙なことに、minpointを0に設定しても機能しますが、を名前付き変数(タイプintegerに設定)に設定できません。どこが間違っていますか?

あなたが使用する必要があります
Set bar = rangeTest.FormatConditions.AddDatabar 

'assign max value + 1 for databar upper bound 
maxValue = Application.WorksheetFunction.Max(rangeTest) + 1 

With bar 
    .BarFillType = xlDataBarFillSolid 
    .BarColor = RGB(189, 215, 238) 'error thrown here (Object doesn't support this property) 
End With 

With rangeTest.FormatConditions(1) 
    .MinPoint.Modify newtype:=0 'xlConditionValueAutomaticMin 
    .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax 'error thrown here (invalid procedure call) 
End With 

答えて

1

MaxPointプロパティ

によって返さ ConditionValueオブジェクトの Modify()方法の BarColor財産

  • xlConditionValueNumbernewvalue引数によって返さFormatColorオブジェクトの

    • Colorプロパティ

    ので、あなたのコードは次のようになります。

    With bar 
        .BarFillType = xlDataBarFillSolid 
        .BarColor.Color = RGB(189, 215, 238) 
    End With 
    
    With rangeTest.FormatConditions(1) 
        .MinPoint.Modify newtype:=0 'xlConditionValueAutomaticMin 
        .MaxPoint.Modify newtype:=xlConditionValueNumber, newvalue:=maxValue  
    End With