![]() |
Checking for existing worksheet name
Morning!
I am doing a little program that would fetch information to a set of sheets, which works OK now. Problem is with checking if the data has been previously fetched, then it should overwrite existing data instead of creating a new set. How do you check if exists stuff in excel. Basic idea. If exists (name) then write to name else new sheet with (name) |
Checking for existing worksheet name
I found this UDF in the forum, I forgot the name of the author, sorry!
Public Function WSExist(wsname As String) As Boolean 'returns true if worksheet exists in the active workbook Dim objWorksheet As Object On Error Resume Next WSExist = False Set objWorksheet = ActiveWorkbook.Sheets(wsname ) If Err = 0 Then WSExist = True End Function Regards, Stefi €˛KtM€¯ ezt Ć*rta: Morning! I am doing a little program that would fetch information to a set of sheets, which works OK now. Problem is with checking if the data has been previously fetched, then it should overwrite existing data instead of creating a new set. How do you check if exists stuff in excel. Basic idea. If exists (name) then write to name else new sheet with (name) |
Checking for existing worksheet name
Here is a sheet check function that you can incorporate
'----------------------------------------------------------------- Function SheetExists(Sh As String, _ Optional wb As Workbook) As Boolean '----------------------------------------------------------------- Dim oWs As Worksheet If wb Is Nothing Then Set wb = ActiveWorkbook On Error Resume Next SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing) On Error GoTo 0 End Function -- HTH Bob Phillips (remove nothere from email address if mailing direct) "KtM" wrote in message oups.com... Morning! I am doing a little program that would fetch information to a set of sheets, which works OK now. Problem is with checking if the data has been previously fetched, then it should overwrite existing data instead of creating a new set. How do you check if exists stuff in excel. Basic idea. If exists (name) then write to name else new sheet with (name) |
Checking for existing worksheet name
Thank you for both replies, both work nicely. Thanks!
|
All times are GMT +1. The time now is 04:53 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com