why not simply delete the sheet if it exists?
add this to your code before you copy the sheet:

    On Error Resume Next
    Application.DisplayAlerts = False
    Sheets("Party Wise").Delete
    Application.DisplayAlerts = True
    On Error GoTo 0
    '------------------------------------------ 

Paul
-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------

 From: Pravin Gunjal <isk1...@gmail.com>
>To: excel-macros@googlegroups.com 
>Sent: Thursday, November 13, 2014 7:53 AM
>Subject: $$Excel-Macros$$ To create a sheet with macro and overwrite on next 
>attempt
>  
>
>
>Hi,
>
>I have recorded a macro to create a new sheet called "Party Wise" based on the 
>info available in sheet called "Pending CN"
>When I go for second attempt it's giving an error because of the sheet name.
>
>Could you please look in to this and arrange a solution to overwrite the data 
>second time in the same sheet: "Party Wise" 
>
>Hope the matter is clear.  Thank you in anticipation.
>
>
>Sub Paryt_Wise()
>'
>' Paryt_Wise Macro
>' Pravin Gunjal
>'
>
>'
>    Sheets("Pending CN").Select
>    Sheets("Pending CN").Copy Before:=Sheets(1)
>    Sheets("Pending CN (2)").Select
>    Sheets("Pending CN (2)").Name = "Party Wise"
>    Cells.Select
>    ActiveWorkbook.Worksheets("Party Wise").Sort.SortFields.Clear
>    ActiveWorkbook.Worksheets("Party Wise").Sort.SortFields.Add Key:=Range( _
>        "C2:C83"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
>        xlSortNormal
>    ActiveWorkbook.Worksheets("Party Wise").Sort.SortFields.Add Key:=Range( _
>        "B2:B83"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
>        xlSortNormal
>    With ActiveWorkbook.Worksheets("Party Wise").Sort
>        .SetRange Range("A1:IV83")
>        .Header = xlYes
>        .MatchCase = False
>        .Orientation = xlTopToBottom
>        .SortMethod = xlPinYin
>        .Apply
>    End With
>    Range("C4").Select
>    ActiveWorkbook.Save
>End Sub
>
>
>Regards
>Pravin Gunjal.
>
-- 
>Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
>=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
>https://www.facebook.com/discussexcel
> 
>FORUM RULES
> 
>1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
>Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
>quick attention or may not be answered.
>2) Don't post a question in the thread of another member.
>3) Don't post questions regarding breaking or bypassing any security measure.
>4) Acknowledge the responses you receive, good or bad.
>5) Jobs posting is not allowed.
>6) Sharing copyrighted material and their links is not allowed.
> 
>NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
>members are not responsible for any loss.
>--- 
>You received this message because you are subscribed to the Google Groups "MS 
>EXCEL AND VBA MACROS" group.
>To unsubscribe from this group and stop receiving emails from it, send an 
>email to excel-macros+unsubscr...@googlegroups.com.
>To post to this group, send email to excel-macros@googlegroups.com.
>Visit this group at http://groups.google.com/group/excel-macros.
>For more options, visit https://groups.google.com/d/optout.
>
>
>    

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to