+ Reply to Thread
Results 1 to 3 of 3

Setting NumberFormat for a cell via a VBA function

  1. #1
    Registered User
    Join Date
    07-18-2017
    Location
    sdadssd
    MS-Off Ver
    2016
    Posts
    2

    Post Setting NumberFormat for a cell via a VBA function

    I'd like to be able to set the display format of data for a cell (for example the caller cell) via a VBA function and I've found posts around the internet that seem to suggest it to be feasible and indeed it is feasible via a macro on a hardcoded cell (for example cell A1) but all my attempts to do it via a function (or a sub that the function calls) have failed. In my code I'm not getting any error, but apparently my setting of NumberFormat seems to be ignored. The fact that setting NumberFormat is ignored is not completely true because when in the string format I provide is present the percent character such as in "0.00%" the new NumberFormat is indeed applied but this is the only case where the thing works. I have also tried using the trick/workaround of invoking the evaluate function to call a sub that sets the NumberFormat for the desidered cell but it is not any more successful.

    Below is an example code I used in one of the many attempts I made.

    Please Login or Register  to view this content.
    My Excel is a Microsoft 365 64-bit version. I specify it because I've found posts on the internet of people declaring that somehow the M365 version introduces further limitations compared to other or older versions of Excel.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,793

    Re: Setting NumberFormat for a cell via a VBA function

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. I hall do it for you THIS time: https://www.mrexcel.com/board/thread...ction.1260388/)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    07-18-2017
    Location
    sdadssd
    MS-Off Ver
    2016
    Posts
    2

    Re: Setting NumberFormat for a cell via a VBA function

    Hello, sorry, I was not aware and did not expect any such pretty unique requirement. I'm not cross posting anything, if I were I would have posted on 10 different forums, I'm simply trying to reach a larger audience of peers. Disregard this post, I prefer searching for help in communities where the only intent is to support and help each other and no one is selling anything.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using NumberFormat function to return a date value
    By samehbijo in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-18-2015, 09:43 AM
  2. ListObject SQL query not setting NumberFormat
    By cheetah05 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-22-2014, 06:08 AM
  3. NumberFormat in cells with if function
    By gajdam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2013, 05:30 PM
  4. Replies: 1
    Last Post: 12-19-2012, 05:29 PM
  5. Setting bold using numberformat
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-03-2010, 10:19 AM
  6. [SOLVED] setting numberformat for -ve numbers
    By bsobaid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2006, 01:35 PM
  7. [SOLVED] Setting NumberFormat within a VBA Module
    By Dominic Olivastro in forum Excel General
    Replies: 3
    Last Post: 04-19-2005, 08:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1