I am using following VB.NET code to copy an excel sheet in a same workbook, but the sheet names are written with (2) every time, what is wrong here?
Dim inp as Integer
inp=Val(Textbox1.Text)
oWB = oXL.Workbooks.Open("D:\testfile.xlsx")
oSheet = oWB.Worksheets("base")
With oWB
For i = 0 To inp - 1
oSheet.Copy(Before:=.Worksheets(i + 1))
With oSheet
.Name = "INP" & i + 1
End With
Next
End With
How to get rid of “(2)” on the sheet name?
Thanks
the following line:
is creating a copy of the sheet you specified. when you create a copy of a sheet, excel adds
(2)to the name to prevent having duplicate sheet names.lets say for example you had a sheet named
basethat you were trying to copy. after processing that line above, you’d end up with the original sheet namedbaseand a new sheet namedbase (2).then, the next few lines of your code:
just rename the original sheet.
try this instead of those two lines: