View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben[_2_] Gord Dibben[_2_] is offline
external usenet poster
 
Posts: 621
Default Copy Sheet and rename it.

Also.............if you run the macro twice on the same invoice sheet, the On
Error Resume Next will prevent the error message about two sheets with same
name.

i.e. if you run the macro twice on Invoice sheet, the second run will produce a
new sheet named Invoice(2) instead of your concatenated name of

ws.Name = Range("K2") & "-" & Range("G1")


Gord

On Tue, 07 Jun 2011 07:28:19 -0700, Gord Dibben wrote:

If this code ever worked as you say, then you must have made a change to the
code at some point.

You have not set lastSheet

Sub Make_Bkup_Copy()
Dim lastSheet As Worksheet
Dim ws as Worksheet
Set lastSheet = Worksheets(Worksheets.Count)
On Error Resume Next
ActiveSheet.Copy after:=lastSheet
Set ws = ActiveSheet
ws.Name = Range("K2") & "-" & Range("G1")

'what is this part designed to do?

' With Target
' If .Value < "" Then
' Name = .Value
' End If
' End With

Sheets("Summary").Columns("A:F").fmTextAlign , 2
Sheets("Summary").Move befo=Sheets("Facture")
Sheets("Facture").Select
Range("K2").Select

End Sub


Gord Dibben MS Excel MVP

On Tue, 7 Jun 2011 08:36:46 -0400, "Cimjet" wrote:

Hi Everyone
I've got this macro that made a backup of my invoice and renamed it, but now
instead of making a backup copy, it renames my original Invoice copy.
Sub Make_Bkup_Copy()
On Error Resume Next
ActiveSheet.Copy after:=lastSheet
Set ws = ActiveSheet
ws.Name = Range("K2") & "-" & Range("G1")

With Target
If .Value < "" Then
Name = .Value
End If
End With

Sheets("Summary").Columns("A:F").fmTextAlign , 2
Sheets("Summary").Move befo=Sheets("Facture")
Sheets("Facture").Select
Range("K2").Select

End Sub
It should copy my Invoice , rename the Tab with cell K2 and G1 ( Invoice number
with name)
Any help would be appreciated.
Thank you
Cimjet