Does a worksheet exist

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)?
 
D

Dave Peterson

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.
 
G

Guest

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?
 

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

Top