VBA Excel DataBar not with positive and negative numbers, two colors, I need minimum negative filled...












0















I have a column in Excel containing positive and negative numbers and I make a data bar. I would like if lets say I have 55, 24, 0, -10 and -45 the 55 to be filled completely with green bar maximum span and -45 the same but red. This is the VBA code that I have so far:



This is visualisation wath I want to achieve:



DataBar



|||||||||||| (green) 12



|||||| (green) 6



|||||||||| (red) -10



|||||||||||||| (red) -14



and so on.....



Function UpdateAmountBars(rng As Range)
Dim min As Double, max As Double
Let min = Application.min(rng)
Let max = Application.max(rng)

rng.FormatConditions.AddDatabar
rng.FormatConditions(rng.FormatConditions.Count).ShowValue = True
rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
With rng.FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueAutomaticMin
.MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
End With

With rng.FormatConditions(1).BarColor
.Color = RGB(100, 255, 100)
.TintAndShade = 0
End With

rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
rng.FormatConditions(1).Direction = xlContext
rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone

With rng.FormatConditions(1).NegativeBarFormat.Color
.Color = RGB(255, 100, 100)
.TintAndShade = 0
End With

End Function


and this is the result of the code:
VBA DataBAR positive negative



Update: I have some progress, now the databars look good but still I don't want the cells to be divided



Function UpdateAmountBars(rng As Range)
Dim min As Double, max As Double, databar As databar
Let min = Application.min(rng)
Let max = Application.max(rng)

Set databar = rng.FormatConditions.AddDatabar
databar.AxisPosition = xlDataBarAxisAutomatic
rng.FormatConditions(rng.FormatConditions.Count).ShowValue = True
rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
With rng.FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueAutomaticMin, newvalue:=min
.MaxPoint.Modify newtype:=xlConditionValueAutomaticMax, newvalue:=max
End With

With rng.FormatConditions(1).BarColor
.Color = RGB(100, 255, 100)
.TintAndShade = 0
End With

rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
rng.FormatConditions(1).Direction = xlContext
rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone

With rng.FormatConditions(1).NegativeBarFormat.Color
.Color = RGB(255, 100, 100)
.TintAndShade = 0
End With
End Function


this is the update result: VBA Data bar axisPosition










share|improve this question





























    0















    I have a column in Excel containing positive and negative numbers and I make a data bar. I would like if lets say I have 55, 24, 0, -10 and -45 the 55 to be filled completely with green bar maximum span and -45 the same but red. This is the VBA code that I have so far:



    This is visualisation wath I want to achieve:



    DataBar



    |||||||||||| (green) 12



    |||||| (green) 6



    |||||||||| (red) -10



    |||||||||||||| (red) -14



    and so on.....



    Function UpdateAmountBars(rng As Range)
    Dim min As Double, max As Double
    Let min = Application.min(rng)
    Let max = Application.max(rng)

    rng.FormatConditions.AddDatabar
    rng.FormatConditions(rng.FormatConditions.Count).ShowValue = True
    rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
    With rng.FormatConditions(1)
    .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
    .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
    End With

    With rng.FormatConditions(1).BarColor
    .Color = RGB(100, 255, 100)
    .TintAndShade = 0
    End With

    rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
    rng.FormatConditions(1).Direction = xlContext
    rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
    rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone

    With rng.FormatConditions(1).NegativeBarFormat.Color
    .Color = RGB(255, 100, 100)
    .TintAndShade = 0
    End With

    End Function


    and this is the result of the code:
    VBA DataBAR positive negative



    Update: I have some progress, now the databars look good but still I don't want the cells to be divided



    Function UpdateAmountBars(rng As Range)
    Dim min As Double, max As Double, databar As databar
    Let min = Application.min(rng)
    Let max = Application.max(rng)

    Set databar = rng.FormatConditions.AddDatabar
    databar.AxisPosition = xlDataBarAxisAutomatic
    rng.FormatConditions(rng.FormatConditions.Count).ShowValue = True
    rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
    With rng.FormatConditions(1)
    .MinPoint.Modify newtype:=xlConditionValueAutomaticMin, newvalue:=min
    .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax, newvalue:=max
    End With

    With rng.FormatConditions(1).BarColor
    .Color = RGB(100, 255, 100)
    .TintAndShade = 0
    End With

    rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
    rng.FormatConditions(1).Direction = xlContext
    rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
    rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone

    With rng.FormatConditions(1).NegativeBarFormat.Color
    .Color = RGB(255, 100, 100)
    .TintAndShade = 0
    End With
    End Function


    this is the update result: VBA Data bar axisPosition










    share|improve this question



























      0












      0








      0








      I have a column in Excel containing positive and negative numbers and I make a data bar. I would like if lets say I have 55, 24, 0, -10 and -45 the 55 to be filled completely with green bar maximum span and -45 the same but red. This is the VBA code that I have so far:



      This is visualisation wath I want to achieve:



      DataBar



      |||||||||||| (green) 12



      |||||| (green) 6



      |||||||||| (red) -10



      |||||||||||||| (red) -14



      and so on.....



      Function UpdateAmountBars(rng As Range)
      Dim min As Double, max As Double
      Let min = Application.min(rng)
      Let max = Application.max(rng)

      rng.FormatConditions.AddDatabar
      rng.FormatConditions(rng.FormatConditions.Count).ShowValue = True
      rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
      With rng.FormatConditions(1)
      .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
      .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
      End With

      With rng.FormatConditions(1).BarColor
      .Color = RGB(100, 255, 100)
      .TintAndShade = 0
      End With

      rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
      rng.FormatConditions(1).Direction = xlContext
      rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
      rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone

      With rng.FormatConditions(1).NegativeBarFormat.Color
      .Color = RGB(255, 100, 100)
      .TintAndShade = 0
      End With

      End Function


      and this is the result of the code:
      VBA DataBAR positive negative



      Update: I have some progress, now the databars look good but still I don't want the cells to be divided



      Function UpdateAmountBars(rng As Range)
      Dim min As Double, max As Double, databar As databar
      Let min = Application.min(rng)
      Let max = Application.max(rng)

      Set databar = rng.FormatConditions.AddDatabar
      databar.AxisPosition = xlDataBarAxisAutomatic
      rng.FormatConditions(rng.FormatConditions.Count).ShowValue = True
      rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
      With rng.FormatConditions(1)
      .MinPoint.Modify newtype:=xlConditionValueAutomaticMin, newvalue:=min
      .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax, newvalue:=max
      End With

      With rng.FormatConditions(1).BarColor
      .Color = RGB(100, 255, 100)
      .TintAndShade = 0
      End With

      rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
      rng.FormatConditions(1).Direction = xlContext
      rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
      rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone

      With rng.FormatConditions(1).NegativeBarFormat.Color
      .Color = RGB(255, 100, 100)
      .TintAndShade = 0
      End With
      End Function


      this is the update result: VBA Data bar axisPosition










      share|improve this question
















      I have a column in Excel containing positive and negative numbers and I make a data bar. I would like if lets say I have 55, 24, 0, -10 and -45 the 55 to be filled completely with green bar maximum span and -45 the same but red. This is the VBA code that I have so far:



      This is visualisation wath I want to achieve:



      DataBar



      |||||||||||| (green) 12



      |||||| (green) 6



      |||||||||| (red) -10



      |||||||||||||| (red) -14



      and so on.....



      Function UpdateAmountBars(rng As Range)
      Dim min As Double, max As Double
      Let min = Application.min(rng)
      Let max = Application.max(rng)

      rng.FormatConditions.AddDatabar
      rng.FormatConditions(rng.FormatConditions.Count).ShowValue = True
      rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
      With rng.FormatConditions(1)
      .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
      .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
      End With

      With rng.FormatConditions(1).BarColor
      .Color = RGB(100, 255, 100)
      .TintAndShade = 0
      End With

      rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
      rng.FormatConditions(1).Direction = xlContext
      rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
      rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone

      With rng.FormatConditions(1).NegativeBarFormat.Color
      .Color = RGB(255, 100, 100)
      .TintAndShade = 0
      End With

      End Function


      and this is the result of the code:
      VBA DataBAR positive negative



      Update: I have some progress, now the databars look good but still I don't want the cells to be divided



      Function UpdateAmountBars(rng As Range)
      Dim min As Double, max As Double, databar As databar
      Let min = Application.min(rng)
      Let max = Application.max(rng)

      Set databar = rng.FormatConditions.AddDatabar
      databar.AxisPosition = xlDataBarAxisAutomatic
      rng.FormatConditions(rng.FormatConditions.Count).ShowValue = True
      rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
      With rng.FormatConditions(1)
      .MinPoint.Modify newtype:=xlConditionValueAutomaticMin, newvalue:=min
      .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax, newvalue:=max
      End With

      With rng.FormatConditions(1).BarColor
      .Color = RGB(100, 255, 100)
      .TintAndShade = 0
      End With

      rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
      rng.FormatConditions(1).Direction = xlContext
      rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
      rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone

      With rng.FormatConditions(1).NegativeBarFormat.Color
      .Color = RGB(255, 100, 100)
      .TintAndShade = 0
      End With
      End Function


      this is the update result: VBA Data bar axisPosition







      excel vba excel-vba conditional-formatting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 14:54







      hammer4

















      asked Nov 24 '18 at 10:59









      hammer4hammer4

      14




      14
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Add and try following code.



          .FormatConditions(1).AxisPosition = None


          Use the above code somewhere here in your code.



          rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
          rng.FormatConditions(1).Direction = xlContext
          rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
          rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone





          share|improve this answer
























          • No it didn't work. The result is the same.

            – hammer4
            Nov 24 '18 at 14:49











          • I understand, you can not do what you expected using one conditional format. You need Two separate conditional formatting for the same range to evaluate positive and negative numbers separately. You may need different approach in codes.

            – lighthouselk
            Nov 24 '18 at 19:32



















          0














          I'm having the same issue with my data bars. The bars are largest for negative values closest to 0 and the bars become smaller the larger the negative number is, which is the opposite of what I want to achieve.






          share|improve this answer
























          • The file which I am working on is for personal use and I havent finished it yet. As soon as I make the data bars working as expected I will share the code.

            – hammer4
            Dec 17 '18 at 17:23











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457433%2fvba-excel-databar-not-with-positive-and-negative-numbers-two-colors-i-need-min%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Add and try following code.



          .FormatConditions(1).AxisPosition = None


          Use the above code somewhere here in your code.



          rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
          rng.FormatConditions(1).Direction = xlContext
          rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
          rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone





          share|improve this answer
























          • No it didn't work. The result is the same.

            – hammer4
            Nov 24 '18 at 14:49











          • I understand, you can not do what you expected using one conditional format. You need Two separate conditional formatting for the same range to evaluate positive and negative numbers separately. You may need different approach in codes.

            – lighthouselk
            Nov 24 '18 at 19:32
















          0














          Add and try following code.



          .FormatConditions(1).AxisPosition = None


          Use the above code somewhere here in your code.



          rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
          rng.FormatConditions(1).Direction = xlContext
          rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
          rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone





          share|improve this answer
























          • No it didn't work. The result is the same.

            – hammer4
            Nov 24 '18 at 14:49











          • I understand, you can not do what you expected using one conditional format. You need Two separate conditional formatting for the same range to evaluate positive and negative numbers separately. You may need different approach in codes.

            – lighthouselk
            Nov 24 '18 at 19:32














          0












          0








          0







          Add and try following code.



          .FormatConditions(1).AxisPosition = None


          Use the above code somewhere here in your code.



          rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
          rng.FormatConditions(1).Direction = xlContext
          rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
          rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone





          share|improve this answer













          Add and try following code.



          .FormatConditions(1).AxisPosition = None


          Use the above code somewhere here in your code.



          rng.FormatConditions(1).BarFillType = xlDataBarFillGradient
          rng.FormatConditions(1).Direction = xlContext
          rng.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
          rng.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 14:17









          lighthouselklighthouselk

          1015




          1015













          • No it didn't work. The result is the same.

            – hammer4
            Nov 24 '18 at 14:49











          • I understand, you can not do what you expected using one conditional format. You need Two separate conditional formatting for the same range to evaluate positive and negative numbers separately. You may need different approach in codes.

            – lighthouselk
            Nov 24 '18 at 19:32



















          • No it didn't work. The result is the same.

            – hammer4
            Nov 24 '18 at 14:49











          • I understand, you can not do what you expected using one conditional format. You need Two separate conditional formatting for the same range to evaluate positive and negative numbers separately. You may need different approach in codes.

            – lighthouselk
            Nov 24 '18 at 19:32

















          No it didn't work. The result is the same.

          – hammer4
          Nov 24 '18 at 14:49





          No it didn't work. The result is the same.

          – hammer4
          Nov 24 '18 at 14:49













          I understand, you can not do what you expected using one conditional format. You need Two separate conditional formatting for the same range to evaluate positive and negative numbers separately. You may need different approach in codes.

          – lighthouselk
          Nov 24 '18 at 19:32





          I understand, you can not do what you expected using one conditional format. You need Two separate conditional formatting for the same range to evaluate positive and negative numbers separately. You may need different approach in codes.

          – lighthouselk
          Nov 24 '18 at 19:32













          0














          I'm having the same issue with my data bars. The bars are largest for negative values closest to 0 and the bars become smaller the larger the negative number is, which is the opposite of what I want to achieve.






          share|improve this answer
























          • The file which I am working on is for personal use and I havent finished it yet. As soon as I make the data bars working as expected I will share the code.

            – hammer4
            Dec 17 '18 at 17:23
















          0














          I'm having the same issue with my data bars. The bars are largest for negative values closest to 0 and the bars become smaller the larger the negative number is, which is the opposite of what I want to achieve.






          share|improve this answer
























          • The file which I am working on is for personal use and I havent finished it yet. As soon as I make the data bars working as expected I will share the code.

            – hammer4
            Dec 17 '18 at 17:23














          0












          0








          0







          I'm having the same issue with my data bars. The bars are largest for negative values closest to 0 and the bars become smaller the larger the negative number is, which is the opposite of what I want to achieve.






          share|improve this answer













          I'm having the same issue with my data bars. The bars are largest for negative values closest to 0 and the bars become smaller the larger the negative number is, which is the opposite of what I want to achieve.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 14 '18 at 17:46









          Matthew ChurchMatthew Church

          62




          62













          • The file which I am working on is for personal use and I havent finished it yet. As soon as I make the data bars working as expected I will share the code.

            – hammer4
            Dec 17 '18 at 17:23



















          • The file which I am working on is for personal use and I havent finished it yet. As soon as I make the data bars working as expected I will share the code.

            – hammer4
            Dec 17 '18 at 17:23

















          The file which I am working on is for personal use and I havent finished it yet. As soon as I make the data bars working as expected I will share the code.

          – hammer4
          Dec 17 '18 at 17:23





          The file which I am working on is for personal use and I havent finished it yet. As soon as I make the data bars working as expected I will share the code.

          – hammer4
          Dec 17 '18 at 17:23


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457433%2fvba-excel-databar-not-with-positive-and-negative-numbers-two-colors-i-need-min%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)