Most of this code is made by the MacroRecorder:
Sub NewWbkTransData()
Dim btn, rght As Long
Dim NewWbk As String
NewWbk = "SomeName"
' Add a new workbook
Application.Workbooks.Add
Range("A1").Select
' Rename the workbook as you cant be sure which name Excel uses
ActiveWorkbook.SaveAs Filename:="C:\" & NewWbk & ".xls"
Windows("OldWbk").Activate
Sheets("Sheet1").Activate
' Either - determine the active range...
Range("A65000").End(xlUp).Select
btn = ActiveCell.Row
Range("IV1").End(xlToLeft).Activate
rght = ActiveCell.Column
Range(Cells(1, 1), Cells(btn, rght)).Select
' .. or select it if you know the range beforehand
' Range("A1:L67").Select
' Copy the selected range...
Selection.Copy
Workbooks(NewWbk).Sheets("Sheet1").Activate
' and Paste it into the new workbook
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End Sub
The OldWbk is, of cause, the one you run the macro from. See if you can use it.
|