Computing.Net > Forums > Office Software > Excle VBA Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excle VBA Help

Reply to Message Icon

Name: Niko9999
Date: April 16, 2005 at 00:11:00 Pacific
OS: WIN XP
CPU/Ram: P-III/128
Comment:

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 Sub

But, it dosen;t work. It just creates anew workbook with all sheets instead of only active sheet.

Can someone help me?

Thanks
Niko



Sponsored Link
Ads by Google

Response Number 1
Name: thanglt
Date: April 29, 2005 at 02:11:13 Pacific
Reply:

Hi Niko.
Pls test with the following code. Good luck.

Private Sub CommandButton1_Click()
Dim wbname As String

wbname = 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").Paste

End Sub


0

Response Number 2
Name: Niko9999
Date: May 4, 2005 at 05:01:57 Pacific
Reply:

Hi thang It

Thanx. It works ok.

Niko


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Excle VBA Help

Help: Excel VBA problem www.computing.net/answers/office/help-excel-vba-problem/7757.html

VBA Help-copy specfic rows from multi sheets www.computing.net/answers/office/vba-helpcopy-specfic-rows-from-multi-sheets/8774.html

excel and access vba help www.computing.net/answers/office/excel-and-access-vba-help/6644.html