Name already excists massage

Triumfera

New Member
Joined
Dec 27, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi,



I have a problem when I am copying sheets using VBA, every time a get this “error massage” saying that the name already exists. It is referring to Data range names, can I use a code to select “yes to all”? I post a pic of the error and my code down below

Skärmbild_20230110_203309.png


Private Sub CommandButton1_Click()

Dim TargetRow1 As Integer
Dim Targetrow2 As Integer
Dim actsheet As String

'GÖR MALL OCH BIGBANG BLAD SYNLIGA
Application.ScreenUpdating = False
ActiveWorkbook.Sheets("Mall").Visible = True
ActiveWorkbook.Sheets("BigBang").Visible = True

'FUNKTION FÖR ÄNDRING AV ARR
If Sheets("BigBang").Range("H3") = "NEW" Then
TargetRow1 = Sheets("BigBang").Range("G2").Value
Targetrow2 = Sheets("BigBang").Range("H2").Value
Else
TargetRow1 = Sheets("BigBang").Range("G4").Value
Targetrow2 = Sheets("BigBang").Range("H4").Value
End If


'DATA INMATNING STARTBLAD
Sheets("start").Range("start_namn").Offset(TargetRow1, 0).Value = namn_org
Sheets("start").Range("start_namn").Offset(TargetRow1, 1).Value = ord_namn
Sheets("start").Range("start_namn").Offset(TargetRow1, 2).Value = SO_namn

'DATA INMATNING BIGBANG
Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, 0).Value = namn_org
Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, 1).Value = CDbl(Unik_del)
Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, 2).Value = ord_namn
Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, 3).Value = ord_tel
Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, 4).Value = ord_post
Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, 5).Value = SO_namn
Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, 6).Value = SO_tel
Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, 7).Value = SO_post

'SKAPA NYTT DATABLAD
If Sheets("BigBang").Range("H3") = "NEW" Then
Set ws = Sheets("Mall")
ws.Copy After:=Sheets("GO")
Set wsNew = Sheets(Sheets("GO").Index + 1)
wsNew.Name = namn_org
Unload Ny_org
Else
Unload Ny_org
End If

'LÅS NYA DATABLADET
Sheets(ActiveSheet.Name).Protect Password:="ABF23ABF"
Sheets(ActiveSheet.Name).Protect userinterfaceonly:=True

'GUIDE KOD
GUIDE = Sheets("BigBang").Range("start_bigbang").Offset(Targetrow2, -1).Value
ActiveSheet.Range("K2").Value = GUIDE

'GÖR MALL OCH BIGBANG OSYNLIGA
Sheets(ActiveSheet.Name).Visible = True
ActiveWorkbook.Sheets("Mall").Visible = False
ActiveWorkbook.Sheets("BigBang").Visible = False
Application.ScreenUpdating = True


End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try adding

VBA Code:
Application.DisplayAlerts = False
    ' Your code goes Here
Application.DisplayAlerts = True
 
Upvote 0

Forum statistics

Threads
1,214,419
Messages
6,119,389
Members
448,891
Latest member
tpierce

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top