Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi All,
I have one open workbook containing many sheets.
I want to copy a range of cells into a new workbook
I create a new workbook using following VBA code.If I use following code it creates a new workbook with a copy of entire active worksheet.
Sub Copysheet()
Dim Fs As String
Fs = Application.GetSaveAsFilename(fileFilter:="xls Files (*.xls), *.xls")
If Fs = "False" Then Exit Sub
Sheets("Sheet1").Copy
ActiveWorkbook.SaveAs Fs
End Sub
However, I want to copy a range of cells ("A10:L100") only instead of entire active sheet. Hence, I wrote following code:Sub Copysheet()
Dim Fs As String
Fs = Application.GetSaveAsFilename(fileFilter:="xls Files (*.xls), *.xls")
If Fs = "False" Then Exit Sub
Sheets("Sheet1").Range("A10:L100").Copy
ActiveWorkbook.SaveAs Fs
End SubBut, it dosen;t work. It just creates anew workbook with all sheets instead of only active sheet.
Can someone help me?
Thanks
Niko

Hi Niko.
Pls test with the following code. Good luck.Private Sub CommandButton1_Click()
Dim wbname As Stringwbname = ActiveWorkbook.name
Set NewBook = Workbooks.Add
With NewBook
.SaveAs Filename:="newbook.xls"
End With
Workbooks(wbname).Activate
Sheets("Sheet1").Range("A1:C10").Copy
Workbooks("newbook.xls").Activate
Sheets("Sheet1").PasteEnd Sub

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |