Insert Excel Sheeet using VBA

J

JP SIngh

Does someone know how to insert a worksheet into a workbook using VBA.

I need to insert a sheet called "Duplicate" on the fly is does not already
exist.

Does anyone know how?

tahnks & regards
J
 
T

Tom Ogilvy

Dim sh as Worksheet
On Error Resume Next
set sh = Worksheets("Duplicate")
On Error goto 0
if sh is nothing then
set sh = worksheets.Add(After:=Worksheets(worksheets.count))
End if

Sh.Activate
 
S

Soo Cheon Jheong

Hi,

Option Explicit
Sub TEST()

Dim SHT As Object

On Error Resume Next
Set SHT = Sheets("Duplicate")
On Error GoTo 0

If SHT Is Nothing Then
Set SHT = Worksheets.Add(After:=Worksheets(Worksheets.Count))
SHT.Name = "Duplicate"
End If

SHT.Activate

End Sub


--
Regards,
Soo Cheon Jheong
_ _
^¢¯^
--
 
Top