473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

export to excel then merge cells perf issue

10
Hi,

I already have a working code where I have an application that queries to SQL then exports it to excel. It also merge cells that have the same value. The only problem I have is that it takes too long to merge the cells since it needs check each cell per column and row. Below is my sample code:

Dim MergeCellRange As Excel.Range
Dim rowcellcount As Integer
Dim colcellcount As Integer
Dim x As Integer
x = 2
For colcellcount = 1 To columnCount
For rowcellcount = 2 To rowcount + 1
If (ExcelWS.Cells(x, colcellcount).Value2 = ExcelWS.Cells(rowcellcount + 1, colcellcount).Value2) And (ExcelWS.Cells(x, colcellcount).Value2 = ExcelWS.Cells(rowcellcount, colcellcount).Value2) Then
If (ExcelWS.Cells(x, colcellcount).Value2 <> ExcelWS.Cells(rowcellcount + 2, colcellcount).Value2) Then
ExcelWS.Cells.Range(ExcelWS.Cells(x + 1, colcellcount), ExcelWS.Cells(rowcellcount + 1, colcellcount)).Value2 = ""
ExcelWS.Cells.Range(ExcelWS.Cells(x, colcellcount), ExcelWS.Cells(rowcellcount + 1, colcellcount)).Merge()
x = rowcellcount + 2
rowcellcount = rowcellcount + 1
End If
End If
Next rowcellcount
x = 2
Next colcellcount


Currently, it takes 45 minutes for 12400 cells to be exported. Any tip on how to speed it up?

Thanks for your help!
Jun 18 '08 #1
1 2544
kadghar
1,295 Expert 1GB
Sure,

Take a look to this HOWTO about reducing time in Excel's VBA.

HTH
Jun 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
1
by: Chris | last post by:
Hi, I am using: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, lcQueryName, strFilePathNamE, True ....to export my query data to an existing excel workbook. Then what i need...
5
by: Maria L. | last post by:
Hi, I need to export the content of a DataGrid (in Windows application in C#), into an Excel spreadsheet. Anyone knows how to do this? Any code snippets would help! thanks a lot, Maria
3
by: Damian Arntzen | last post by:
I'm a beginner to moderate programmer who's fiddling around with automating Excel, in particular after being able to have the user fill out a form and it then generate the workbook. I can't quite...
4
by: Hans [DiaGraphIT] | last post by:
Hi! I want to export a dataset to an excel file. I found following code on the net... ( http://www.codeproject.com/csharp/Export.asp ) Excel.ApplicationClass excel = new ApplicationClass();...
6
by: Gunawan | last post by:
Dear All, I have create an excel (COM Object) using this code Excel.Application xls = new Excel.Application(); but I can not remove it from memory although I have using close and quit ...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
3
by: jmarcrum | last post by:
I want to export a report (that contains two separate queries, 1. Current year data, and 2. split-year data) from access into excel, but everytime I run my code and export the data to excel, it looks...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.