View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
p[_2_] p[_2_] is offline
external usenet poster
 
Posts: 6
Default GetOpenFileName bug

tro find out if a sheet is unique, iterate through the Worksheets
collection:

Function SheetIsUnique(ByVal SheetName As String)
On Error Resume Next
Dim iSheetCount
bSheetNameIsUnique = True
For iSheetCount = 1 To Sheets.Count
If LCase(Sheets(iSheetCount).Name) =
LCase(SheetName) Then
bSheetNameIsUnique = False
Exit For
End If
Next
SheetIsUnique = bSheetNameIsUnique

End Function

to search for a value:

sub findsomething(somethingtofind as string)
dim CurRow
CurRow=1
With ActiveSheet.UsedRange
Do Until IsEmpty(Cells(CurRow, 1))
If Cells(CurRow, 1).Value < "" Then
If Cells(CurRow, 2).Value = somethingtofind
Then
dosomething
end if
end if
currow=currow+1
Loop
end with
end sub
"Chuck Waterfield" wrote in message
om...
Hi Markus,

Yes, I use this same routine in my workbook when I know the sheetname.
The issue here is that I'm importing a list of formulas that I've
exported from another workbook. I don't know how to do a routine to
go through any formula and identify and isolate any possible worksheet
names so that I can test them with this procedure. (I expect some
highly complex series of string searches would do so, but I think it
would take me forever... maybe a routine exists?)

So instead, I use a different routine I've found on this newsgroup,
that pastes the formula in a cell, tests if it gives a #REF error. If
so, it assumes the worksheet doesn't exist. If it doesn't then it
clearly does.

Thanks for your assistance,

Chuck Waterfield

"Markus L" wrote in message

...
Chuck Waterfield wrote:
I have a situation where I need to insert formulas containing
sheetnames, and test for situations where the sheetname may not exist
in the workbook.


Take a look at the IsSheet function published by Jake in this newsgroup

back
in 1998.
Works great for me.

http://groups.google.com/groups?q=is...elm=35F53650.D
61F0218%40wwa.com&rnum=4
In case the link above doesn't work, here's the function:

Public Function IsSheet(strSheetName As String)
IsSheet = False
For Each ws In Worksheets
If ws.Name = strSheetName Then
IsSheet = True
Exit For
End If
Next ws
End Function


Markus