I need to apply below code on about 3000 files and each file have 300K rowsx 4columns. With the code below each file take about 5 minutes to complete, so to do this on all files will take me couple days. Is there a way to make this happen faster?
(I need to also add, I'm very new to VBA and below code is a copy/paste code but it works, just very slow for the purpose.)
Any help or direction were to read more about it is appreciated, Thank you.
(I need to also add, I'm very new to VBA and below code is a copy/paste code but it works, just very slow for the purpose.)
Any help or direction were to read more about it is appreciated, Thank you.
Code:
Sub Macro1openwaveformfiles()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+r
'
Dim MyFolder As String
Dim myfile As String
Dim folderName As String
Dim c As Long
Dim k As Long
c = 4
k = 2
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
folderName = .SelectedItems(1)
End If
End With
myfile = Dir(folderName & "\*.txt")
Do While myfile <> ""
Workbooks.OpenText Filename:=folderName & "\" & myfile, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Cells.Select
Selection.Replace What:=".", Replacement:=".", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A300038").Select
ActiveCell.FormulaR1C1 = "Max"
Range("A300039").Select
ActiveCell.FormulaR1C1 = "Min"
Range("B300038").Select
ActiveCell.FormulaR1C1 = "=MAX(R[-300003]C:R[-1]C)"
Range("B300038").Select
Selection.AutoFill Destination:=Range("B300038:C300038"), Type:= _
xlFillDefault
Range("B300038:C300038").Select
Selection.AutoFill Destination:=Range("B300038:C300039"), Type:= _
xlFillDefault
Range("B300038:C300039").Select
Range("B300039").Select
ActiveCell.FormulaR1C1 = "=MIN(R[-300003]C:R[-1]C)"
Range("C300039").Select
ActiveCell.FormulaR1C1 = "=MIN(R[-300003]C:R[-1]C)"
Range("C300040").Select
ActiveWindow.SmallScroll Down:=12
Range("B300040").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=R[-2]C-R[-1]C"
Range("B300040").Select
Selection.AutoFill Destination:=Range("B300040:C300040"), Type:= _
xlFillDefault
Range("B300040:C300040").Select
Range("A300040").Select
ActiveCell.FormulaR1C1 = "Diff"
Range("A300041").Select
ActiveWorkbook.SaveAs Filename:=folderName & "\" & Replace(myfile, ".txt", ".xlsx"), FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Range("B300038:B300040").Select
Selection.Copy
ActiveWindow.Close
Windows("Joined_PC_Level.xlsx").Activate
Cells(3, c).Select
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True
c = c + 1
'Ensure Workbook has closed before moving on to next line of code
DoEvents
'Get next file name
myfile = Dir
Loop
End Sub