Thread
:
Worksheet Codenames Passing to Function
View Single Post
#
5
Posted to microsoft.public.excel.programming
Nigel[_2_]
external usenet poster
Posts: 735
Worksheet Codenames Passing to Function
Hi Peter
Thanks for the fixes to the code. Sorry to confuse but in addition
I have the codename which is shAIF, if I store the value shAIF in a string
(myString) and pass that it does not work?
So
FindReport(shAIF, searchText) ' works as shAIF resolves to a sheet
But
FindReport(myString, searchText) 'does not work!
Any help please.
--
Regards,
Nigel
"Peter T" <peter_t@discussions wrote in message
...
Where or why do you need a sheet's code name. It's a bit confusing, you
say
"this fails to pass the codename shAIF to the function"
but you havn't attempted to pass it, the first argument in your function
expects a worksheet object.
Sheet1, without quotes, could be passed if that's what you want, to refer
to
a sheet within same project as the code (ie hardcoded and potentially
unreliable)
or are you saying you know the codename as a string and want to use that
to
get a reference to the sheet object.
In passing, your function would work with following changes (subject to
receiving a worksheet object) -
change
With xSh
to
With searchSh
change
Set c = .Cells.Find(xFind, LookIn:=xlValues)
to
Set c = .Cells.Find(searchText , LookIn:=xlValues)
change
FindReport = c.address.Row
to
FindReport = c.Row
If you want to retrieve the codename from the worksheet object
Dim sCodeName as string
sCodeName = searchSh.Codename
NOTE cannot return codename of newly inserted sheet unless the VBE is
open,
or the wb has been subsequently saved or quite a lot more work depending
on
xl version.
Regards,
Peter T
"Nigel" wrote in message
...
Hi All
I wish to pass a worksheet codename to function. How do I do this?
So far......this fails to pass the codename shAIF to the function
Sub Test
MsgBox FindReport(shAIF, "New Report")
End Sub
Function FindReport(searchSh as Worksheet, searchText as String) as Long
FindReport = 0
Dim c
With xSh
Set c = .Cells.Find(xFind, LookIn:=xlValues)
If Not c Is Nothing Then
FindReport = c.address.Row
End If
End With
End Function
--
Regards,
Nigel
Reply With Quote
Nigel[_2_]
View Public Profile
Find all posts by Nigel[_2_]