Solved

TickLabels.Numberformat not working in Excel VBA

Posted on 2014-02-26
6
1,726 Views
Last Modified: 2014-02-26
Hi

I'm working on some analytics tools built by another developer.  In the spreadsheet, there are some charts linked to a combobox which is used to set the scaling (millions, billions, trillions) of the Y-Axis.

The combobox is then linked to a macro which scales the Y-axis based on the user selection and also applies a specific number format relevant to the scale in use.

However, for some reason it seems that the number format does not get accepted (no error is thrown, it is just ignored) or applied to the axis when a different scale is selected.

Even more curiously, if you query the number format of the Y-axis in the Immediate Window of the VBE after changing the selection of the scale, it actually returns the number format that it should have although it does not display it visually.

Furthermore, if you format the axis manually and apply the desired number format, then the correct format is displayed.

Is this a known issue or bug or is there some other subtle issue at play?

I attached a sample file which shows the problem:  the blue cell displays the ordinal number which corresponds to the scale selected from the combobox.  The orange cells constitute the source range of the combobox and the green cells are the cells that contain the numberformat that should be applied based on the scale applied.

The VBA code to format and scale the chart's Y-axis is linked to the combobox. (please see attached)

Thanks
Vyyk
Chart-Sample.xlsm
0
Comment
Question by:Vyyk_Drago
  • 4
  • 2
6 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,$

pls try

Sub ScaleChartYAxis()

    Dim chrt As Chart
    
    Set chrt = ActiveSheet.ChartObjects("Chart 1").Chart

    With chrt.Axes(xlValue)
    a = .TickLabels.NumberFormat
        Select Case Range("L1").Value
            Case 1
                .DisplayUnit = xlMillions
            Case 2
                .DisplayUnit = xlThousandMillions
            Case 3
                .DisplayUnit = xlMillionMillions
        End Select
        .TickLabels.NumberFormatLocal = Range("N1").Offset(Range("L1").Value).Value
        Debug.Print .TickLabels.NumberFormat
    End With

End Sub

Open in new window

Regards
0
 

Author Comment

by:Vyyk_Drago
Comment Utility
I've requested that this question be deleted for the following reason:

I resolved the problem myself.
0
 

Author Closing Comment

by:Vyyk_Drago
Comment Utility
Awesome, thanks!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Vyyk_Drago
Comment Utility
Moderator

Can you please keep this open and not delete?

For some reasons the answer from Rgonzo1971 did not show up until after I had requested to close the question.

All points should be awarded to Rgonzo1971.

Thanks
Vyyk
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Or if you want to use NumberFormat instead of NumberFormatLocal

use

Millions      #\,##0_);(#\,##0)
Billions      #\,##0.0_);(#\,##0.0)
Trillions      #\,##0.00_);(#\,##0.00)
Regards
0
 

Author Comment

by:Vyyk_Drago
Comment Utility
Excellent, thanks - that's very helpful!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now