Does a worksheet exist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When a worksheet is named and copied from one workbook to another workbook
via a macro, is it possible to check whether that worksheet name already
exists and if so to paste over it and not make a new sheet, as in Worksheet
Name (1)?
 
You could...

But if you really want the new sheet in that other workbook, how about just
deleting it first?

Dim wksName as string
dim testwks as worksheet
wksname = activesheet.name

application.displayalerts = false 'not "are you sure prompt"
on error resume next 'in case it isn't there
otherworkbook.worksheets(wksname).delete
on error goto 0
application.displayalerts = true

Then do the copy.
 
This does seem to be a much simpler solution! To clarify tho, did you intend
for this code to go into the workbook that the sheet is being copied FROM or
TO? Since you're using ActiveSheet I'm guess it should go in the FROM
workbook, which means I would need to move my macro with the OnTime function
there as well?
 
Back
Top