Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4081548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:04:30+00:00 2026-05-20T18:04:30+00:00

I am using VBA to strip out the headers for an import. The issue

  • 0

I am using VBA to strip out the headers for an import.

The issue I am having now is that the process is truncating leading 0’s from dates. Even something as simple as pointing me to a description of all the methods available for the Cells(#, #) object would help.


 ' VBScript source code
Option Explicit
REM We use "Option Explicit" to help us check for coding mistakes

REM the Excel Application
Dim objExcel
REM the path to the excel file
Dim excelPath
REM how many worksheets are in the current excel file
Dim worksheetCount
Dim counter
REM the worksheet we are currently getting data from
Dim currentWorkSheet
REM the number of columns in the current worksheet that have data in them
Dim usedColumnsCount
REM the number of rows in the current worksheet that have data in them
Dim usedRowsCount
Dim row
Dim column
REM the topmost row in the current worksheet that has data in it
Dim top
REM the leftmost row in the current worksheet that has data in it
Dim left
Dim Cells
REM the current row and column of the current worksheet we are reading
Dim curCol
Dim curRow
REM the value of the current row and column of the current worksheet we are reading
Dim word

REM the text file writer that I will output to to see what this process is creating
Dim objFSOExcel
REM the output worksheet
Dim outputWorksheet
Dim objWorkbook

REM where is the Excel file located?
excelPath = "C:\Documents and Settings\kitchenjt\My Documents\Professional Development\input\11TRVL.xls"

REM Create an invisible version of Excel
Set objExcel = CreateObject("Excel.Application")

REM create the Output Excel file
Set objFSOExcel = CreateObject("Excel.Application")
Set objWorkBook = ObjFSOExcel.Workbooks.Add
Set outputWorksheet = objWorkBook.Worksheets(1)
'outputWorksheet.Name = "SafeTRVL"

REM don't display any messages about documents needing to be converted
REM from  old Excel file formats
objExcel.DisplayAlerts = 0
objFSOExcel.DisplayAlerts = 0


REM open the excel document as read-only
REM open (path, confirmconversions, readonly)
objExcel.Workbooks.open excelPath, false, true


REM How many worksheets are in this Excel documents
REM changed to only get the first worksheet
workSheetCount = 1'objExcel.Worksheets.Count

Dim outrow
outrow = 1

REM Loop through each worksheet
For counter = 1 to workSheetCount
    'txtFile.writeLine("-----------------------------------------------")
    'txtFile.writeLine("Reading data from worksheet " & counter & vbCRLF)

    Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)
    REM how many columns are used in the current worksheet
    usedColumnsCount = currentWorkSheet.UsedRange.Columns.Count
    REM how many rows are used in the current worksheet
    usedRowsCount = currentWorkSheet.UsedRange.Rows.Count

    REM What is the topmost row in the spreadsheet that has data in it
    top = currentWorksheet.UsedRange.Row
    REM What is the leftmost column in the spreadsheet that has data in it
    left = currentWorksheet.UsedRange.Column


    Set Cells = currentWorksheet.Cells
    REM Loop through each row in the worksheet 
    For row = 0 to (usedRowsCount-1)

        REM Loop through each column that has an intial value that starts with T in the worksheet 
        REM only look at rows that are in the "used" range
        curRow = row+top
        word = Cells(curRow,left).Value
        REM display the column on the screen
        if word <> "" and InStr(1,word,"T",1) > 0 and Cells(curRow, left+1).value <> "" then
            For column = 0 to usedColumnsCount-1
                REM only look at columns that are in the "used" range
                curCol = column+left
                REM get the value/word that is in the cell 
                word = Cells(curRow,curCol).Value
                REM add the column to the new excel file
                outputWorksheet.Cells(outrow, curCol).Value = word' = Cells(curRow,curCol)
            Next
            outrow = outrow + 1
        end if
    Next

    REM We are done with the current worksheet, release the memory
    Set currentWorkSheet = Nothing
Next

objWorkbook.SaveAs("C:\Documents and Settings\kitchenjt\My Documents\Professional Development\input\CleanExcel.xls")
objWorkbook.Close
objFSOExcel.Quit
objExcel.Workbooks(1).Close
objExcel.Quit

Set currentWorkSheet = Nothing
REM We are done with the Excel object, release it from memory
Set objExcel = Nothing
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:04:31+00:00Added an answer on May 20, 2026 at 6:04 pm

    Set the output cell’s NumberFormat to text before writing to it:

    Cells(curRow, curCol).NumberFormat = "@"
    REM get the value/word that is in the cell 
    word = Cells(curRow,curCol).Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm querying a SQL db from excel using vba, that all works fine but
I am using VBA to paste charts/graphs from Access to PowerPoint. Once pasted, I
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
Using VBA I am loading an 8-byte floating point number from an array of
Hi I'm using VBA in Excel and need to pass in the values from
I'm using VBA to create a FileOpenDialog object so that the user can select
I'm trying to find all controls on msform from c# using VBA extensibility interop.
I'm using VBA to do some further formatting to a generated CSV file that's
I want to paste an image from clipboard to an excel cell using vba.
I'm having trouble with changing the file access mode on Excel workbooks using VBA.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.