I am so very close. Now my issue is saving the workbook. I want to use SaveCopyAs rather then SaveAs, but I get an error with the way I am using it.
Please help!
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("G Code").Select
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.Select
Selection.Copy
Sheets.Add.Name = "Final Code"
Sheets("Final Code").Select
ActiveSheet.Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs sSaveAsFilePath, xlTextWindows, _
CreateBackup:=False
ActiveWorkbook.Save
Application.ScreenUpdating = False
ActiveWindow.SelectedSheets.Delete
ActiveWindow.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Windows("Mill Radius CNC Code Generator").Activate
Sheets("Calculations").Select
End Sub
Bookmarks