More efficient code than this?

C

chrismv48

Hello all,

I recorded this macro using Excel's Macro Recorder and making tweaks
afterwards. After reading up on VBA I have a feeling that the code is
probably bloated with unecessary commands/lines. It also runs fairly slow on
my computer.

What the macro does is copy a worksheet to a new book, copies that whole
sheet and pastes special as values. Then it does a save as and closes...

Sub Macro1()

Sheets("Invoice").Select
Sheets("Invoice").Copy
Cells.Select
Range("C11").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

ActiveWorkbook.SaveAs "C:\Documents and Settings\GIT " & Range("G8") & ".xls"
ActiveWorkbook.Close
End Sub
 
J

Jim Thomlinson

Sub Macro1()
Sheets("Invoice").Copy
cells.value = cells.value 'works on active sheet
wtih ActiveWorkbook
.SaveAs "C:\Documents and Settings\GIT " & Range("G8") & ".xls"
.Close
end with
End Sub
 
C

chrismv48

This is actually slower and errors at the end??

Jim Thomlinson said:
Sub Macro1()
Sheets("Invoice").Copy
cells.value = cells.value 'works on active sheet
wtih ActiveWorkbook
.SaveAs "C:\Documents and Settings\GIT " & Range("G8") & ".xls"
.Close
end with
End Sub
 
J

Jim Thomlinson

Try this...

Sub Macro1()
Sheets("Invoice").Copy
usedrange.value = usedrange.value 'works on active sheet
with ActiveWorkbook
.SaveAs "C:\Documents and Settings\GIT " & Range("G8") & ".xls"
.Close
end with
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top