Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excel 8.0
I am testing a means of identifying / selecting (and then copying) a worksheet within the current workbook. The report sheets use a standard naming format - Report Name - Mmm-YY e.g. "Sales Report - Dec-03", "Orders In Report - Dec-03", "Orders Out Report - Dec-03" etc etc I am asking the code to confirm the sheets existence. Sub CheckReport() Dim ReportSheetMonth As String, ReportSheetType as String, ReportSheetName as String 'Users enter the Month Required ReportSheetMonth = UCase(InputBox("Please enter the Month-Year of the reports you wish to check [mmm-yy]" & Chr$(13) & Chr$(13) & "eg Mar-04", "Report Period")) ' I have other code here that checks the validity of the entry. An example of an entry would be say "Dec-03" ReportSheetType = "Sales Report - " ReportSheetName = ReportSheetType & ReportSheetMonth If WorksheetExists(ReportSheetName) = True Then _ ' see below GoTo ReportExists MsgBox "Report does NOT exist" ' do what is required as a result Exit Sub TatReportExists: MsgBox "Report does exist" ' do what is required as a result Exit Sub To test for the worksheet's existence I use the following Function. Public Function WorksheetExists(WSName As String, Optional WB As Workbook = Nothing) As Boolean On Error Resume Next WorksheetExists = CBool(Len(IIf(WB Is Nothing, ThisWorkbook, WB).Worksheets(WSName).Name)) End Function The above does not work. But if I paste the actual name of the worksheet (eg Sales Report - Dec-03) directly into the code above i.e. If WorksheetExists("Sales Report - Dec-03") = True Then etc etc it does work. What am I doing wrong here? Any help gratefully appreciated. WSF |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Referring to a variable cell on another sheet | Excel Worksheet Functions | |||
Referring to a variable file name | Excel Discussion (Misc queries) | |||
referring a worksheet | Excel Worksheet Functions | |||
referring to other worksheet | Excel Worksheet Functions | |||
Referring to a local or global variable or constant dynamically? | Excel Programming |