Rx_
Nothing In Moderation
- Local time
- Today, 14:28
- Joined
- Oct 22, 2009
- Messages
- 2,803
Does anyone have any improvemnets for speed to suggest?
Some of my Excel reports are 20,000 rows (with autofilter and other features for users to conduct analysis)
It seems that I remember a Select Case is suppose to run much faster.
And, perhaps there is more efficient and faster code?
Background:
Createing a user form that lets users design SQL used to run a query (not shown) to place in a recordset. After using CopyFromRecordset to move the date to Excel:
The following code shows how to select a range (one column in this case) and to format each cell based on the value in the cell.
Some of my Excel reports are 20,000 rows (with autofilter and other features for users to conduct analysis)
It seems that I remember a Select Case is suppose to run much faster.
And, perhaps there is more efficient and faster code?
Background:
Createing a user form that lets users design SQL used to run a query (not shown) to place in a recordset. After using CopyFromRecordset to move the date to Excel:
The following code shows how to select a range (one column in this case) and to format each cell based on the value in the cell.
Code:
Dim [FONT=Calibri]Spanish_Inquisition[/FONT] As Excel.Range
' The column header is on row 4, data starts on line 5 (thus the offset)
' Not shown - when CopyFromRecordset used to take data from Access
' to Excel - save the number of records in variable
intMaxRecordCount
' ObjXL is an object variable to create an instance of Excel
Set [FONT=Calibri][FONT=Calibri]Spanish_Inquisition[/FONT][/FONT]= objXL.Range("K5:K" & (intMaxRecordCount + 5))
For Each Cell In [FONT=Calibri]Spanish_Inquisition[/FONT]
' perhaps a Select Case would be better - anyone care to try?
If Cell.Value = "State" Then
Cell.Interior.ColorIndex = 3
End If
If Cell.Value = "Federal" Then
Cell.Interior.ColorIndex = 4
End If
If Cell.Value = "County" Then
Cell.Interior.ColorIndex = 18
End If
If Cell.Value <> "State" And Cell.Value <> "Federal" And Cell.Value <> "County" And Cell.Value <> "Miscellaneous" Then
Cell.Interior.ColorIndex = xlNone
End If
Next
Set [FONT=Calibri]Spanish_Inquisition[/FONT]= Nothing