ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Question to overwriting a sheet (https://www.excelbanter.com/excel-programming/300742-question-overwriting-sheet.html)

Philipp Oberleitner

Question to overwriting a sheet
 

I have the error that when i want to execute the macro again i get an error
messsage cause teh sshet already exist , is there a way to overwrite it ?

Sub ShowOpenTickets()
Const Blatt1 = "2004-05-28_Auswertung_D2_VDF"
ActiveWorkbook.Worksheets.Add.Name = "Open Tickets"
Const Blatt2 = "Open Tickets"
Dim i As Integer
Dim iAnz As Integer

Application.ScreenUpdating = False
Sheets(Blatt1).Activate
Range("D1").Select
iAnz = 0
i = 0

Do Until i = ActiveSheet.UsedRange.Rows.Count
If ActiveCell.Value = "in work" Or ActiveCell.Value = "assigned" Then
Selection.EntireRow.Copy
Sheets(Blatt2).Activate
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
Sheets(Blatt1).Select
ActiveCell.Offset(1, 0).Select
iAnz = iAnz + 1
Else
ActiveCell.Offset(1, 0).Select
End If
i = i + 1
Loop
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox "Es wurden " & iAnz & " Sätze übertragen"

End Sub



Harald Staff

Question to overwriting a sheet
 
Hi Philipp

Sheet names must be unique in a workbook, because you may have formulas
saying
=Open Tickets!A1
So if you have to create a new sheet with this distinct name, you have to
rename the old one to something else first. This "something else" also has
to be unique (... and so on ;-)

HTH. Best wishes Harald

"Philipp Oberleitner" skrev i melding
...

I have the error that when i want to execute the macro again i get an

error
messsage cause teh sshet already exist , is there a way to overwrite it ?

Sub ShowOpenTickets()
Const Blatt1 = "2004-05-28_Auswertung_D2_VDF"
ActiveWorkbook.Worksheets.Add.Name = "Open Tickets"
Const Blatt2 = "Open Tickets"
Dim i As Integer
Dim iAnz As Integer

Application.ScreenUpdating = False
Sheets(Blatt1).Activate
Range("D1").Select
iAnz = 0
i = 0

Do Until i = ActiveSheet.UsedRange.Rows.Count
If ActiveCell.Value = "in work" Or ActiveCell.Value = "assigned" Then
Selection.EntireRow.Copy
Sheets(Blatt2).Activate
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
Sheets(Blatt1).Select
ActiveCell.Offset(1, 0).Select
iAnz = iAnz + 1
Else
ActiveCell.Offset(1, 0).Select
End If
i = i + 1
Loop
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox "Es wurden " & iAnz & " Sätze übertragen"

End Sub






All times are GMT +1. The time now is 08:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com