Ok, I have a work book that imports data from a server. The data ultimately ends up on a worksheet after being manipulated. The first text column may or may not contain text in a cell. Some are empty some have text. The adjacent column contains a formula that evaluates the text cell. The issue is that when a data cell is empty, the formula text can flow over the empty cell. The only way I can find to stop it to put a "space" character in the empty cells.
The problem is this can take a long time to run. A query could take any where from a standard retrieval can take anywhere from 6-16 minutes to run based on the data set. Of the total time, 30/40% of the time is based on this one activity
Currently I use the code below to add a space to the empty cells.
Any help with a method to speed this up would be helpful. Although not shown, auto-calculation and screen updating are turned off earlier in the code.
The first data location starts on I10 and currently goes out to BF10. The last row used is variable.
I10 = Text
J10 = Formula
K10 = Text
L10 = Formula
o
o
BE = Text
BF= Formula
This is my current code that I call.
-------------------------------------------------------------------------------------
Public Sub Add_Spaces()
On Error GoTo Add_Spaces_Error
lastrow1 = ActiveSheet.Cells(Rows.count, "A").End(xlUp).Row
path3 = "I10" & ":" & "BG" & lastrow1
Range(path3).Select
' This is a test
' Selection.SpecialCells(xlCellTypeBlanks).Select
' Selection.FormulaR1C1 = " "
' This is current formulas
Selection.Replace What:="", Replacement:=" ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Application.StatusBar = "Done adding spaces"
Exit Sub
Add_Spaces_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Add_Spaces of Module XYZ"
End Sub
↧