worldofinterest
New Member
- Joined
- Jun 24, 2014
- Messages
- 3
I receive a weekly csv file from a database where several pieces of data have 3 or 4 empty spaces in a cell, depending on the database character type length.
I have set a routine to loop through 3 columns of data to trim each cell in turn (sample attached).
This routine, even with screen updating disabled is very slow.
Can you please suggest a faster method to trim the cells.
Many thanks
David
I have set a routine to loop through 3 columns of data to trim each cell in turn (sample attached).
This routine, even with screen updating disabled is very slow.
Can you please suggest a faster method to trim the cells.
Many thanks
David
Code:
Option Explicit
Sub Trim_Cells()
'This routine trims cells in Columns 1, 3 and 5 using a Do-Until Loop
'Declare Variables
Dim tStart As Date
Dim tFinish As Date
Dim tRunTime As Double
Dim R As Integer 'Row Number
'Switch off screen refresh
Application.ScreenUpdating = 0
'Record Start Time
tStart = Now()
'Set user message in the staus bar
Application.StatusBar = "Trimming Vendor Codes. Please be patient"
R = 7 'First data row
'Loop through all job records
Do Until Cells(R, 5) = "" 'Test for empty cell
Cells(R, 1) = Trim(Cells(R, 1)) 'Trim Client_Code
Cells(R, 3) = Trim(Cells(R, 3)) 'Trim Vendor_Code
Cells(R, 5) = Trim(Cells(R, 5)) 'Trim Booking Ref
R = R + 1
Loop
'Record the finish time
tFinish = Now()
'Reset status bar message
Application.StatusBar = False
'Calculate and show time taken for routine to run.
tRunTime = (tFinish - tStart) * 24 * 60 * 60
tRunTime = MsgBox("Time taken for routine is " & Round(tRunTime, 5) & " seconds", , "Run Time")
End Sub