View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Copy part of worksheet in VBA

Hi Ruatha

Then you create a new workbook with one sheet and copy the selection in this sheet
This example save the file in your default folder

Sub Save_Range()
Dim source As Range
Dim dest As Workbook
Dim strdate As String

Set source = Range("C5:K34")

Application.ScreenUpdating = False
Set dest = Workbooks.Add(xlWBATWorksheet)
source.Copy
With dest.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
' Paste:=8 will copy the column width in Excel 2000 and higher
' If you use Excel 97 use the other example
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
End With

strdate = Format(Now, "dd-mm-yy h-mm-ss")
With dest
.SaveAs "Selection of " & ThisWorkbook.Name _
& " " & strdate & ".xls"
.Close False
End With
Application.ScreenUpdating = True
End Sub

If you want to mail it see
http://www.rondebruin.nl/mail/folder1/mail4.htm

Or
http://www.rondebruin.nl/mail/folder2/mail4.htm




--
Regards Ron De Bruin
http://www.rondebruin.nl



"Ruatha" wrote in message
...

Ron De Bruin helped me with the following code

Code:
--------------------
Sub test()
Dim wb As Workbook
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb.Sheets(1)
.UsedRange.Copy
.UsedRange.PasteSpecial xlPasteValues
.Cells(1).Select
Application.CutCopyMode = False
End With
wb.SaveAs "C:\" & wb.Sheets(1).Name & ".xls"
wb.Close False
End Sub
--------------------


It copies a worksheet to a seperate file.
But what if I only want to copy C5:K34 to the new file (content not
functions, as above)


--
Ruatha
------------------------------------------------------------------------
Ruatha's Profile: http://www.excelforum.com/member.php...o&userid=31083
View this thread: http://www.excelforum.com/showthread...hreadid=551749