Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Excel, VB and Column formatting

Excel, VB and Column formatting

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RichardGrimmer
    wrote on last edited by
    #1

    Hi guys. Am working on an app that needs to dump some product codes into a col in Excel (2K3). Unfortunately, some of the prod codes are numeric, some textual. Naturally, when adding through code, Excel left justifies the text ones, and right justifies the numerics. Have tried to add a "'" before the data, and this does in fact cause excel to L-Justify the data, however, in 2K3, it causes an error smart tag stating that "the number in this cell has been formatted as text or is preceded by an apostrophe" What I'd really like to do is format the entire Column as a Text only column - any ideas how to do this from code - is simple using the Excel front end, but can't find a way to do it from code....any ideas? "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

    J 1 Reply Last reply
    0
    • R RichardGrimmer

      Hi guys. Am working on an app that needs to dump some product codes into a col in Excel (2K3). Unfortunately, some of the prod codes are numeric, some textual. Naturally, when adding through code, Excel left justifies the text ones, and right justifies the numerics. Have tried to add a "'" before the data, and this does in fact cause excel to L-Justify the data, however, in 2K3, it causes an error smart tag stating that "the number in this cell has been formatted as text or is preceded by an apostrophe" What I'd really like to do is format the entire Column as a Text only column - any ideas how to do this from code - is simple using the Excel front end, but can't find a way to do it from code....any ideas? "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

      J Offline
      J Offline
      jimpar
      wrote on last edited by
      #2

      Here is how I format columns in excel using a CExcel class module: Set objExcel = New CExcel With objExcel .OpenExcelFile strFilename, "Visit List" .StoreExcelRange "A1", lngRecsProcessed + 3, 13, varDataArray .FreezePanes "A3", True .SetExcelRowBold 1 .SetExcelCellWidthAutoFit .FormatColumn "A", "000000000" .FormatColumn "E", "$#,##0.00" .CloseExcelFile End With Set objExcel = Nothing Here is the actual code in the FormatColumn m_objWorksheet.Columns(p_strColumn).NumberFormat = p_strFormat To see exactly what code excel uis doing you could record a macro in Excel as you format the column. The code you need will be in side the macro code and is easily migratable to VB

      R 1 Reply Last reply
      0
      • J jimpar

        Here is how I format columns in excel using a CExcel class module: Set objExcel = New CExcel With objExcel .OpenExcelFile strFilename, "Visit List" .StoreExcelRange "A1", lngRecsProcessed + 3, 13, varDataArray .FreezePanes "A3", True .SetExcelRowBold 1 .SetExcelCellWidthAutoFit .FormatColumn "A", "000000000" .FormatColumn "E", "$#,##0.00" .CloseExcelFile End With Set objExcel = Nothing Here is the actual code in the FormatColumn m_objWorksheet.Columns(p_strColumn).NumberFormat = p_strFormat To see exactly what code excel uis doing you could record a macro in Excel as you format the column. The code you need will be in side the macro code and is easily migratable to VB

        R Offline
        R Offline
        RichardGrimmer
        wrote on last edited by
        #3

        Yeah - appreciate your help, but what I was after was something allong the following lines: oWorkSheet.Cells(lRow,lCol).Errors(xlNumberAsText).Ignore = True Thanks for the help tho....:-) "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups