+ Reply to Thread
Results 1 to 4 of 4

Number Format Macro

  1. #1
    Registered User
    Join Date
    08-20-2014
    Location
    san francisco, ca
    MS-Off Ver
    Excel2021
    Posts
    28

    Number Format Macro

    I am trying to run a macro that makes all of the numeric cells in the used range (ie not the entire worksheet) have the format _(#,##0_)_%;(#,##0)_%;_("?"_)_%;_(@_)_%

    But, it is not working. I am receiving an error code "unable to set number format property of the range class"

    The code i am trying is below. Any thoughts on where i am going wrong?


    Sub FormatNumericCells()
    Dim cell As Range
    For Each cell In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants, xlNumbers).Cells
    If Not IsDate(cell.Value) And Not cell.MergeCells Then
    cell.NumberFormat = "_(#,##0_)_%"";""_(#,##0)_%"";""_(""?"")_%"";""_(@_)_%"
    End If
    Next cell
    End Sub

  2. #2
    Forum Contributor
    Join Date
    10-30-2019
    Location
    Bistrita, Romania
    MS-Off Ver
    2019; 365
    Posts
    231

    Re: Number Format Macro

    This works for me:
    Please Login or Register  to view this content.
    To show your appreciation
    Click ★ Add reputation!

  3. #3
    Registered User
    Join Date
    08-20-2014
    Location
    san francisco, ca
    MS-Off Ver
    Excel2021
    Posts
    28

    Re: Number Format Macro

    no, i need code to exclude from the formatting change those cells which are already in a date format.

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Number Format Macro

    Hi wbsgn12,

    Try below code ...
    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

+ 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. [SOLVED] Macro to format phone number
    By cjamps in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-09-2017, 07:22 AM
  2. Macro number format
    By simo12447 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-16-2015, 11:05 AM
  3. macro to change a number and its format
    By Emma_B in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2014, 02:46 PM
  4. Format Number with Macro
    By tmill29 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-13-2014, 02:17 PM
  5. [SOLVED] Help to Create Macro for changing to number format
    By naveenmarapaka in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-05-2012, 08:07 AM
  6. Macro is changing the number format
    By kynel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-18-2012, 05:50 AM
  7. Replies: 1
    Last Post: 05-18-2006, 11:45 PM

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