Hi all,
I've been working away on trying to get a solution for this and have been scouring the message boards but can't quite find what I need.
I am currently running two macros, the first imports a text file into columns A to E (there are ~100k lines so it flips to Sheet 2 once the end of Sheet 1 is reached). Modified version of a macro I found on your great board :
This macro takes ~10 minutes to run, which is manageable. However I then need to run a second macro to reduce the contents of any cells >40 characters to 40 characters. Here is what I am using, again sourced from the board and modified:
This takes a hefty 30 minutes + to run on only one of the sheets!
I was wondering
a) Can I alter the first macro to limit the length of the text strings it copies in?
or
b) I there any way to speed up this slow second macro?
Any assistance is much appreciated!
I've been working away on trying to get a solution for this and have been scouring the message boards but can't quite find what I need.
I am currently running two macros, the first imports a text file into columns A to E (there are ~100k lines so it flips to Sheet 2 once the end of Sheet 1 is reached). Modified version of a macro I found on your great board :
Code:
Sub ImportBankfile()
Application.ScreenUpdating = False
' Calls BANKFILE.TXT and copies data as required
Dim iFreeFile As Integer, i As Long, path As String, InputLine
Dim ws As Worksheet, LineArray, t As Date
t = Now
Set ws = ActiveSheet
Reset
iFreeFile = FreeFile
path = ThisWorkbook.path
Open path & "\" & "BANKFILE.txt" For Input As #iFreeFile
Application.ScreenUpdating = False
i = 8
Do While Not EOF(iFreeFile)
Line Input #iFreeFile, InputLine
LineArray = Split(InputLine, vbTab)
ws.Range(Cells(i, 1), Cells(i, 5)).Value = LineArray
i = i + 1
If i > 65536 Then
Sheets("Sheet2").Activate
Set ws = ActiveSheet
i = 9
End If
Loop
' Saves the workbook and closes BANKFILE.TXT
ThisWorkbook.Save
Close #iFreeFile
' Re-enables Screen Updating and returns a message box detailing how long it took to run
Application.ScreenUpdating = True
MsgBox "Time elapsed" & vbTab & Format(Now - t, "hh:mm:ss")
End Sub
This macro takes ~10 minutes to run, which is manageable. However I then need to run a second macro to reduce the contents of any cells >40 characters to 40 characters. Here is what I am using, again sourced from the board and modified:
Code:
Sub Line_Format()
' Disables ScreenUpdating - Records Current Time
t = Now
ccount = ActiveSheet.Cells.SpecialCells(xlCellTypeConstants).Count
Dim i As Long
' Sheet - Limits the information in each cell to 40 characters
Sheets("Sheet1").Activate
For Each cell In ActiveSheet.Cells.SpecialCells(xlCellTypeConstants)
With cell
.Value = Left(cell.Value, 40)
End With
loopcount = loopcount + 1
Application.StatusBar = "Processing...." & Format(loopcount / ccount, "0.0%") & " Complete"
Next
' Re-enables ScreenUpdating - MsgBox Advises Time Elapsed
MsgBox "Time elapsed" & vbTab & Format(Now - t, "hh:mm:ss")
End Sub
This takes a hefty 30 minutes + to run on only one of the sheets!
I was wondering
a) Can I alter the first macro to limit the length of the text strings it copies in?
or
b) I there any way to speed up this slow second macro?
Any assistance is much appreciated!