HERE IS THE CODE USED TO CONVERT TXT into EXCEL.
I NEED TO ADD CONDITIONAL "A" CELLS TO BE ALWAYS START WITH "1" and "E" value for added cell to be ZERO without changing "E" values.
Sub d_spacing_code()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
'Optimize Macro Speed
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
'Retrieve Target Folder Path From User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
'In Case of Cancel
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
'Target File Extension (must include wildcard "*")
myExtension = "*.txt"
'Target Path with Ending Extention
myFile = Dir(myPath & myExtension)
'Loop through each Excel file in folder
Do While myFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(Filename:=myPath & myFile)
Workbooks.OpenText Filename:=myPath & myFile _
Rows("6:13").Select
Selection.Delete Shift:=xlUp
Range("A1:C5").Select
Selection.ClearContents
Range("A1").Select
ActiveCell.FormulaR1C1 = "Pixel Size [um]"
Range("A2").Select
ActiveCell.FormulaR1C1 = "Camera Length [mm]"
Range("A3").Select
ActiveCell.FormulaR1C1 = "Wavelength [A]"
Range("A4").Select
ActiveCell.FormulaR1C1 = "Average d-spacing [A]"
Range("A5").Select
ActiveCell.FormulaR1C1 = "Standard Deviation"
Range("C1").Select
ActiveCell.FormulaR1C1 = "172"
Range("C2").Select
ActiveCell.FormulaR1C1 = "3342.06"
Range("C3").Select
ActiveCell.FormulaR1C1 = "1.0332"
Range("C4").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(E8:E16)"
Range("C5").Select
ActiveCell.FormulaR1C1 = "=STDEV.S(E8:E16)"
Range("A6").Select
ActiveCell.FormulaR1C1 = "Order"
Range("B6").Select
ActiveCell.FormulaR1C1 = "# of Pixels"
Range("D6").Select
ActiveCell.FormulaR1C1 = "d [A]"
Range("E6").Select
ActiveCell.FormulaR1C1 = "d*Order"
Range("D7").Select
ActiveCell.FormulaR1C1 = "=R3C3/(2*SIN(0.5*ATAN(RC[-2]*R1C3/(1000*R2C3))))"
Range("D7").Select
Selection.AutoFill Destination:=Range("D7:D" & Range("B" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
Range("D7:D18").Select
Range("E7").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*RC[-4]"
Range("E7").Select
Selection.AutoFill Destination:=Range("E7:E" & Range("A" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
Range("E7:E18").Select
Range("C4").Select
ActiveCell.FormulaR1C1 = "=AVERAGEIF(R[4]C[2]:R[12]C[2],""<>0"")"
Range("C5").Select
ActiveCell.FormulaR1C1 = "=STDEV.S(R[3]C[2]:R[10]C[2])"
Range("C6").Select
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Name & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
'Get next file name
myFile = Dir
Loop
'Message Box when tasks are completed
MsgBox "Task Complete!"
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub