jeremypyle
Board Regular
- Joined
- May 30, 2011
- Messages
- 174
Hi,
I'm very new to VBA. Normally just work with formulas
I am trying to create a VBA code that does the following:
1) copy info from current worksheet
2) create then worksheet and paste into into that worksheet
3) Then save that new worksheet as a new workbook. I want the name of the new workbook to be the name of the new worksheet. ie. sheet3,sheet4, etc
4) once the new workbook has been created, I want to delete the new worksheet that was created in step 2
How can I do this?
Step 1 in my code works okay.
But step 2 doesn't work.
And step 3 I don't know how to create.
Please see my code below:
Sub Copy_current_sheet_into_a_new_sheet_then_save_new_sheet_as_new_workbook_then_delete_the_sheet_that_was_created()
'
' Macro5 Macro
'
' step 1 - copying info to new worksheet
Range("A1:L9999").Select
Range("H7").Activate
Selection.Copy
Sheets.Add After:=ActiveSheet
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.ScreenUpdating = False
Range("H1").Select
Columns("H:H").ColumnWidth = 18.14
Columns("C:C").Select
Application.CutCopyMode = False
Selection.NumberFormat = "0"
Columns("H:H").Select
Selection.NumberFormat = "0"
' step 2 - Save new worksheet as a new workbook
Application.ScreenUpdating = False
Dim ws As Worksheet
ws.Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & ws.Name
' step 3 - now how do I delete the new worksheet that was created in step 1
End Sub
I'm very new to VBA. Normally just work with formulas
I am trying to create a VBA code that does the following:
1) copy info from current worksheet
2) create then worksheet and paste into into that worksheet
3) Then save that new worksheet as a new workbook. I want the name of the new workbook to be the name of the new worksheet. ie. sheet3,sheet4, etc
4) once the new workbook has been created, I want to delete the new worksheet that was created in step 2
How can I do this?
Step 1 in my code works okay.
But step 2 doesn't work.
And step 3 I don't know how to create.
Please see my code below:
Sub Copy_current_sheet_into_a_new_sheet_then_save_new_sheet_as_new_workbook_then_delete_the_sheet_that_was_created()
'
' Macro5 Macro
'
' step 1 - copying info to new worksheet
Range("A1:L9999").Select
Range("H7").Activate
Selection.Copy
Sheets.Add After:=ActiveSheet
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.ScreenUpdating = False
Range("H1").Select
Columns("H:H").ColumnWidth = 18.14
Columns("C:C").Select
Application.CutCopyMode = False
Selection.NumberFormat = "0"
Columns("H:H").Select
Selection.NumberFormat = "0"
' step 2 - Save new worksheet as a new workbook
Application.ScreenUpdating = False
Dim ws As Worksheet
ws.Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & ws.Name
' step 3 - now how do I delete the new worksheet that was created in step 1
End Sub