Copy active sheet range and paste into new workbook

VaYooper

New Member
Joined
Mar 12, 2015
Messages
31
I've seen various threads where many different variations of what I'm trying to do are explained but all seem to be just a tad bit different. What I'm trying to accomplish is write a script that will copy columns A:L in the active worksheet and paste into a new workbook. I would also like to receive the save as prompt with prefilled filename and file type(xlsx). After saving the new file, I would like to close it and be brought back to the previous active sheet. Not very far along as you see in the code below but its a start. Thanks

Code:
Sub AssessSave()
   Sheets("Overdue Assessments").Copy
   Application.Dialogs(xlDialogSaveAs).Show
   ActiveWorkbook.Close
End Sub
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
This is probably clunky but I've made some progress. My only hiccup is instead of this new workbook saving with the predefined name I would like a Save As prompt popup with this predefined information just in case they want to edit the name prior to it saving.
Code:
Sub AssessSave()
Dim newWB As Workbook, currentWB As Workbook
Dim newS As Worksheet, currentS As Worksheet

'Copy the data you need
Set currentWB = ThisWorkbook
Set currentS = currentWB.Sheets("Overdue Assessments")
currentS.Range("A:K").Select
Selection.Copy

'Create a new file that will receive the data
Set newWB = Workbooks.Add
    With newWB
        Set newS = newWB.Sheets("Sheet1")
        newS.Range("A1").PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        newS.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Columns("K:K").Select
        Selection.NumberFormat = "[$-409]d-mmm-yy;@"
        Range("A1:K1").Select
        Selection.Font.Bold = True
    Range("A1:K1").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With ActiveWindow
        .SplitColumn = 0
        .SplitRow = 1
    End With
    ActiveWindow.FreezePanes = True
    Range("A1").Select
        'Save in xlsx
        Application.DisplayAlerts = False
        .SaveAs fileName:="Overdue Assessments" & Format(Date, "MM-DD-YYYY"), FileFormat:=51
        Application.DisplayAlerts = True
    End With
   ActiveWorkbook.Close
    Range("A1").Select
End Sub
 
Last edited:
Upvote 0
How about
Code:
Sub VaYooper()
    
    Sheets("Overdue Assessments").Copy
    With Application.FileDialog(2)
        .InitialFileName = "Afile.xlsx"
        If .Show = -1 Then .Execute
    End With
    ActiveWorkbook.Close
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top