Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Number format to show both zeros AND blanks


Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2010, 09:11 AM
HappyJoni's Avatar
HappyJoni HappyJoni is offline
Centurion
 
Join Date: Jun 2003
Location: New Jersey
Posts: 150
Question Number format to show both zeros AND blanks


I have a VB6 program that's transfering data into Excel.. some of the data has zeros and blanks that need to be transfered over exactly as is, with both zeros AND blanks. I've tried many different number formats and it seems I can only show either zeros OR blanks, in some instances, Excel changes my blanks to zeros.. NOT what I want, I need both... anyone know what format will work??
Reply With Quote
  #2  
Old 03-31-2010, 09:18 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline
Out Of Office

Retired Moderator
* Expert *
 
Join Date: Mar 2005
Location: London, UK
Posts: 3,398
Default

Hi,

How are you transferring the data into Excel?
__________________
RAD Excel Blog
Reply With Quote
  #3  
Old 03-31-2010, 09:23 AM
HappyJoni's Avatar
HappyJoni HappyJoni is offline
Centurion
 
Join Date: Jun 2003
Location: New Jersey
Posts: 150
Default

I'm a little embaressed to show my code because I know it's not the best and there are probably more errors... right now I'm just trying to fix one error at a time...

That being said, here it is...

Code:
Command1.Enabled = False
Command4.Enabled = True
Row = 0
'Col = 1
Start = Text1.Text
End1 = (Text2.Text - Text1.Text) + 1

'open Excel and create a new worksheet
    Dim oXLApp As Excel.Application         'Declare the object variables
    Dim oXLBook As Excel.Workbook
    Dim oXLSheet As Excel.Worksheet

    Set oXLApp = New Excel.Application    'Create a new instance of Excel
    
    If FirstTime = True Then
        Set oXLBook = oXLApp.Workbooks.Add    'Add a new workbook
    Else
        Set oXLBook = oXLApp.Workbooks.Open(Text4.Text) 'Open an existing workbook
    End If
    
    Set oXLSheet = oXLBook.Worksheets(1)  'Work with the first worksheet
   

    
  'This file is the input
    INfile = FreeFile()
    Open Text3.Text For Input As #INfile
         
Do While Not EOF(INfile) 'Continue to read and process MAINFILE until EOF is reached
            
        Line Input #INfile, Rec 'Read a record
        Row = Row + 1
        
  
    'read data into worksheet
    Xfer = (Mid(Rec, Start, End1))
    oXLSheet.Cells(Row, Col).Value = Xfer
    oXLSheet.Cells(Row, Col).NumberFormat = "space"
  
        
Loop
    
    Reset
    MsgBox "column created"
    
    
        'Save the workbook to a new file:
        Set oXLSheet = Nothing                        'disconnect from the Worksheet
        oXLBook.SaveAs Text4.Text  'Save (and disconnect from) the Workbook
        oXLBook.Close SaveChanges:=False
        Set oXLBook = Nothing
        oXLApp.Quit                                   'Close (and disconnect from) Excel
        Set oXLApp = Nothing
        FirstTime = False
    

End Sub

Last edited by Colin Legg; 03-31-2010 at 09:25 AM. Reason: added code tags
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->