Consulting

Results 1 to 2 of 2

Thread: NumberFormat of a table column

  1. #1
    VBAX Regular
    Joined
    Sep 2021
    Posts
    12
    Location

    NumberFormat of a table column

    Dear Gurus,
    adding a column to a table, I'd like to set the number format of the data in advance - numbers with two decimal digits or accounting.

    Here below the code I'm using and in which I'd like to add a statement that selects the cells of the column changing their format.

    Set ws2 = Worksheets("Resources")
    Set table2 = ws2.ListObjects("Table2")
    
    
    With table2
        For i = 1 To durY
            .ListColumns.Add
            colCount = .ListColumns.Count
            .HeaderRowRange(colCount).NumberFormat = "yyyy"
            .HeaderRowRange(colCount).Value = DateAdd("yyyy", i - 1, stdate)
        Next i
    End With
    I've tried adding, before the next, the statement:

            .ListColumns(colCount2).DataBodyRange.NumberFormat = "Accounting"
    But this is giving me an Application-defined error.

    Could you please let me know where/ what I'm making wrong?

    Thanks in advance,
    A.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    I don't think number formats have names like Styles


    Try ... .NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)"


    for Accounting
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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