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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:13:07+00:00 2026-06-08T12:13:07+00:00

I am currently using VBA to run a stored procedure and stored data that

  • 0

I am currently using VBA to run a stored procedure and stored data that been extracted to table. Then, the VBA will query all the data in the data accordingly and put it into excel.

Here the problem, it takes so long for the VBA to extract all data (around 100k rows of data) into excel. Is there any other way to speed up the process? Below is part of my code. The one in bold is the insertion to excel code.

'Row number where data inserting starts
        Do
            current_sheet = owb.ActiveSheet

            With current_sheet
                'Insert header to worksheet in first row, ie. A1, B1, C1
                For i = 0 To data_cols.GetLength(0) - 1
                    cell = data_cols(i, 0) & header_row_num 'Change to header_row_num
                    .Range(cell).Value = data_cols(i, 1)
                Next i
            End With

            row_count = header_row_num + 1 'Change the first row count to a row after header_row_num
            'Insert data to worksheet
            While rs.EOF = False

                With current_sheet
                    'Set format of specic columns before inserting data

                    .Columns("A").NumberFormat = "@"

                    .Columns("B").NumberFormat = "@"

                    .Columns("C").NumberFormat = "@"

                    .Columns("D").NumberFormat = "@"

                    .Columns("E").NumberFormat = "@"

                    .Columns("F").NumberFormat = "@"

                    .Columns("G").NumberFormat = "@"

                    .Columns("H").NumberFormat = "@"

                    .Columns("I").NumberFormat = "@"

                    .Columns("J").NumberFormat = "@"

                    .Columns("K").NumberFormat = "@"

                    .Columns("L").NumberFormat = "@"

                    .Columns("M").NumberFormat = "@"

                    .Columns("N").NumberFormat = "@"

                    .Columns("O").NumberFormat = "@"

                    .Columns("P").NumberFormat = "@"

                    .Columns("Q").NumberFormat = "@"

                    .Columns("R").NumberFormat = "@"

                    .Columns("S").NumberFormat = "@"

                    **'Start inserting data
                    For i = 0 To data_cols.GetLength(0) - 1
                        'Get the cell name
                        cell = data_cols(i, 0) & row_count
                        'Populate data to the cell
                        If IsDBNull(rs.Fields(data_cols(i, 2)).Value()) Then
                            .Range(cell).Value = " "
                        Else
                            .Range(cell).Value = rs.Fields(data_cols(i, 2)).Value()
                        End If
                    Next i
                End With
                rs.MoveNext()
                'Indicates next row
                row_count += 1**

                If row_count > 60000 Then
                    owb.Worksheets.Add(, current_sheet)
                    need_new_sheet = True
                    Console.WriteLine("Added new sheet to workbook...")
                    Exit While
                Else
                    need_new_sheet = False
                End If

            End While
        Loop While (need_new_sheet And rs.EOF = False)

In case certain variable you need to know.

row_count = header_row_num + 1 'Change the first row count to a row after header_row_num

oxl = CreateObject("Excel.Application")
    oxl.Visible = False
    owb = oxl.Workbooks.Add

Dim data_cols(,) As String = {{"A", "Name", "NAME"}, _
                           {"B", "Age", "AGE"}}  (Not real columns, example)

Any advice or thoughts would be greatly appreciate. Thanks in advance 🙂

  • 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-08T12:13:08+00:00Added an answer on June 8, 2026 at 12:13 pm

    Filling up 100k rows in Excel will definitely take time.

    This is what you can do to minimize the time

    1. Use oxl.ScreenUpdating = False in the beginning of the macro and set it to True in the end.
    2. You might want to store the data in the array and then writing the array to Excel in one go in the end. This would definitely decrease the execution time
    3. Excel 2007 onwards Excel has a row limitation of 1048576 rows so you might want to take that into consideration if you cross that limit.
    4. Console.WriteLine("Added new sheet to workbook...") is VB.net. Use Debug.print if you are using VBA.
    5. BTW this will not have significant effect on the speed but you can write the following code

    Which is

    .Columns("A").NumberFormat = "@"
    .Columns("B").NumberFormat = "@"
    '
    '
    '
    .Columns("R").NumberFormat = "@"
    .Columns("S").NumberFormat = "@"
    

    as

    .Columns("A:S").NumberFormat = "@"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using VBA, I need to unpivot data that is currently in delimited text files
I'm querying a SQL db from excel using vba, that all works fine but
The following Visio macro (using VBA) rotates the currently selected shape: ActiveWindow.Selection.Rotate90 How can
I currently have data that I am splitting into multiple sheets and allowing the
I am using the DoCmd.TransferText in MS-Access-2010 VBA to export a table to a
I'm using excel VBA. I want to press a button that opens another file
Using Application.Quit in Excel VBA is supposed to initiate the default quit procedure, which
I am trying to run a stored procedure on my SQL server. I think
I am currently using VBA code which was originally intended for an excel document.
I am trying to write some vba code in Excel to query a table

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.