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 8351513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:39:12+00:00 2026-06-09T08:39:12+00:00

I need to import some CSVs into Excel spreadsheet, the row/column numbers of the

  • 0

I need to import some CSVs into Excel spreadsheet, the row/column numbers of the CSVs are different for each of them. The problem is that some values are long digit strings like
341235387313289173719237217391,

Excel will treat those values as (double) numbers, and then results in lost of data.

My way to solve it is to use the following vbafunction to do the job:

Sub readCSV(f As TextStream, sh As Worksheet)
    i = 1
    Do
        l = Trim(f.ReadLine)
        If l = "" Then Exit Sub 'skip the last empty line(s)
        l = Mid(l, 2, Len(l) - 1)
        ss = Split(l, """,""")
        For j = LBound(ss) To UBound(ss) 'j starts from 0
            Dim a As Range
            With sh.Cells(i, j + 1)
                .NumberFormat = "@" 'Force to text format
                .Value = ss(j)
            End With
            DoEvents 'Avoid blocking the GUI
        Next j
        i = i + 1
    Loop Until f.AtEndOfStream
End Sub

The problem is the performance. It is much slower than importing the data through Data->From Text or just open the CSVs directly.

Are there any way to do it more efficiently?

  • 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-06-09T08:39:13+00:00Added an answer on June 9, 2026 at 8:39 am

    You can format/write each line in one shot:

    Sub readCSV(f As TextStream, sh As Worksheet)
    
         Dim i As Long
         Dim ss, l
         i = 1
    
        With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
        End With
    
        Do
            l = Trim(f.ReadLine)
            If l = "" Then Exit Sub 'skip the last empty line(s)
            l = Mid(l, 2, Len(l) - 1)
            ss = Split(l, """,""")
    
            With sh.Cells(i, 1).Resize(1, (UBound(ss) - LBound(ss)) + 1)
                If (i-1) Mod 100 = 0 Then .Resize(100).NumberFormat = "@"
                .Value = ss
            End With
    
            i = i + 1
        Loop Until f.AtEndOfStream
    
        With Application
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
        End With
    
    
    End Sub
    

    EDIT: after testing, the real performance killer is setting the cell format to text- revised code to set this in blocks of 100 lines instead of each line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to import some Excel spreadsheets into Java objects. I will use POI
I need to to import some csv files into excel 2010 and create a
I need to import some global functions into each page on my asp.net 4
I need to import some ANSI C code into a project I'm working on.
I need to import a lot of data into a sql server database. Some
I have an application that uses DBF files and I need to import them
I'm trying to import some Shapefile mapping data into Sql2008. Before I do that,
I'm working with Spring/Hibernate (using NetBeans 6.9.1). I need to import Excel sheet into
I need to periodically import some data into my rails app on Heroku. The
I need to import some data from a excel file and a folder with

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.