Insert Excel Sheeet using VBA

  • Thread starter Thread starter JP SIngh
  • Start date Start date
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
 
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
 
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
_ _
^¢¯^
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top