Hello all, I assumed wrong what was causing the issue and had another thread changing how my values were copied to the sheet.
My issue is that the code below is outputting a text file with many rows of blank lines after the last line of text. Is there a way to remove the extra lines when it is saved?
Private Sub CommandButton1_Click()
Dim sSaveAsFilePath As String
Dim c As Range
Dim rng As Range
Dim sRange1 As String
Dim sRange2 As String
Dim sRange3 As String
Dim sRange4 As String
Dim sRange5 As String
sRange1 = "C:\Users\" & Environ$("Username") & _
"\Desktop\"
sRange2 = Sheets("Calculations").Range("B2")
sRange3 = "x"
sRange4 = Sheets("Calculations").Range("B1")
sRange5 = "rad.g"
Dim ans As Long
sSaveAsFilePath = sRange1 + sRange2 + sRange3 + sRange4 + sRange5
Application.Sheets("Final Code").Select
ActiveSheet.Unprotect Password:="UNLOCK"
Application.Sheets("Final Code").Cells.ClearContents
Application.Sheets("G Code").Select
'testing code here
For Each c In Sheets("G Code").Range("B1:B20000")
If Not Len(c) = 0 Then
If rng Is Nothing Then
Set rng = c.Offset(, -1).Resize(1, 8)
Else
Set rng = Union(rng, c.Offset(, -1).Resize(1, 8))
End If
End If
Next c
rng.Copy Sheets("Final Code").Range("A1")
'end test
' Sheets("G Code").Range("A1:H20000").Copy
'Sheets("Final Code").Select
' ActiveSheet.Range("A1").Select
' Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
' Application.DisplayAlerts = False
Sheets("Final Code").Copy
ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows, _
CreateBackup:=False
ActiveWorkbook.Save
ActiveWindow.Close
Windows("Mill Radius CNC Code Generator").Activate
Sheets("Final Code").Select
ActiveSheet.Protect Password:="UNLOCK"
Sheets("Calculations").Select
Application.DisplayAlerts = True
End Sub
Thanks in advance!
Bookmarks