margentieri
Board Regular
- Joined
- Apr 13, 2016
- Messages
- 50
Hello all,
I have created a VBA script that pulls data from one document, and exports that data into several different files. There is a blank row in my data (which I want to keep, row 17, i.e. the blank row in between the "Quad#" values and the PlateData value), but instead of showing up in the text file as an empty row (i.e. just a carriage return on that line, nothing else), it appears as a line with 24 tabs, corresponding to the 24 columns of data. How can I modify my code so that this empty row is actually empty, instead of populated with tabs? Thanks!
I tried to include examples of my data, but this forum seems to be automatically deleting the tabs from the line in question, so it's rather moot to paste it here if it does not show the problem. Happy to answer any questions or send example data files. Thanks!
I have created a VBA script that pulls data from one document, and exports that data into several different files. There is a blank row in my data (which I want to keep, row 17, i.e. the blank row in between the "Quad#" values and the PlateData value), but instead of showing up in the text file as an empty row (i.e. just a carriage return on that line, nothing else), it appears as a line with 24 tabs, corresponding to the 24 columns of data. How can I modify my code so that this empty row is actually empty, instead of populated with tabs? Thanks!
Code:
Sub Split1536Loop()
Dim Wb As Workbook
Dim OutoutFile As Variant
Dim FileNameExt As Variant
Dim FileNameNoExt As String
Dim OutputFile As Variant
Dim Quad1 As Variant
Dim Quad2 As Variant
Dim Quad3 As Variant
Dim Quad4 As Variant
Dim PlateData As Variant
FileNameExt = Application.GetOpenFilename(FileFilter:="Text Files (*.txt; *.csv), *.txt; *.csv", Title:="Please select a file")
If FileNameExt = False Then
MsgBox "Operation Cancelled", vbOKOnly
Exit Sub
End If
FileNameNoExt = Left(FileNameExt, Len(FileNameExt) - 4)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Wb = Workbooks.Open(FileNameExt)
Quad1 = Range(Cells(1, 1), Cells(16, 24)).Value
Quad2 = Range(Cells(1, 25), Cells(16, 48)).Value
Quad3 = Range(Cells(17, 1), Cells(32, 24)).Value
Quad4 = Range(Cells(17, 25), Cells(32, 48)).Value
PlateData = Range(Cells(34, 1), Cells(36, 12)).Value
For i = 1 To 4
Set OutputFile = Workbooks.Add
OutputFile.Windows(1).Visible = False
OutputFile.Activate
If i = 1 Then
Range(Cells(1, 1), Cells(16, 24)) = Quad1
Range(Cells(18, 1), Cells(20, 12)) = PlateData
ElseIf i = 2 Then
Range(Cells(1, 1), Cells(16, 24)) = Quad2
Range(Cells(18, 1), Cells(20, 12)) = PlateData
ElseIf i = 3 Then
Range(Cells(1, 1), Cells(16, 24)) = Quad3
Range(Cells(18, 1), Cells(20, 12)) = PlateData
ElseIf i = 4 Then
Range(Cells(1, 1), Cells(16, 24)) = Quad4
Range(Cells(18, 1), Cells(20, 12)) = PlateData
End If
OutputFile.SaveAs Filename:=FileNameNoExt & "_Quad" & i & ".txt", FileFormat:=42
OutputFile.Close
Next i
Wb.Close
ThisWorkbook.Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I tried to include examples of my data, but this forum seems to be automatically deleting the tabs from the line in question, so it's rather moot to paste it here if it does not show the problem. Happy to answer any questions or send example data files. Thanks!