Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing Worksheet tab as an argument.

Hi,

I have the following function requiring ws as a worksheet...


Code
-------------------
Function LastCell(ws As Worksheet)
...
End Functio
-------------------


This works fine if I call it using Sheet1, Sheet2,...

I want to pass worksheet tab names to the function. Is it possible?

Regard

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default Passing Worksheet tab as an argument.

Hi,

You want to pass the worksheet name as argument, so the function argument is
a string.
Function LastCell(ws As Stringt)
worksheets(ws).range( ;;;)
End Function

call the function

return = LastCell(sheet1.name)
or
return = LastCell("YOUR sheet name")
or
return = LastCell(worksheets("YOUR sheet name").name)

Regards

JY

"Kashizzz " wrote in message
...
Hi,

I have the following function requiring ws as a worksheet...


Code:
--------------------
Function LastCell(ws As Worksheet)
...
End Function
--------------------


This works fine if I call it using Sheet1, Sheet2,...

I want to pass worksheet tab names to the function. Is it possible?

Regards


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Passing Worksheet tab as an argument.

Hi Kashizzz,


One way:

Function LastCell(strWSName As String) As Range
Dim ws As Worksheet
Set ws = Worksheets(strWSName)
'your code

End Function


---
Regards,
Norman



"Kashizzz " wrote in message
...
Hi,

I have the following function requiring ws as a worksheet...


Code:
--------------------
Function LastCell(ws As Worksheet)
...
End Function
--------------------


This works fine if I call it using Sheet1, Sheet2,...

I want to pass worksheet tab names to the function. Is it possible?

Regards


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Passing Worksheet tab as an argument.

Not certain, examining the other replies, that I have understood your
question.
It seem to me that you simply want to know the name of the worksheet
within the 'LastCell' function. If that is so, you already have it. Try
....
msgbox ws.name

"Kashizzz " wrote in message
...
Hi,

I have the following function requiring ws as a worksheet...


Code:
--------------------
Function LastCell(ws As Worksheet)
...
End Function
--------------------


This works fine if I call it using Sheet1, Sheet2,...

I want to pass worksheet tab names to the function. Is it possible?

Regards


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing Worksheet tab as an argument.

Thanks for your replies folks....

The issue was that the LastCell function needed ws to be passed as a
worksheet object.

Excel expects the name of the sheet, (which is defaulted as Sheet1 fo
the first, Sheet2 for the second and so on, and found under Projec
Explorer (Ctrl+R) - Properties (F4)- ) under (Name).

I passed the object using the following code:

Code
-------------------
Worksheets("SheetName").Activate
LastRow = LastCell(ActiveSheet).Ro
-------------------


...and this worked!!!

Regards

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a UDF as an argument to a UDF puff Excel Discussion (Misc queries) 3 February 23rd 06 09:46 PM
Need help passing an array as an argument blc[_3_] Excel Programming 3 August 4th 04 10:35 PM
Passing range as argument Jan Kronsell[_2_] Excel Programming 3 September 3rd 03 12:31 PM
Passing an argument to a quote Zach Excel Programming 1 July 25th 03 04:16 AM
Passing an argument to a quote Zach Excel Programming 1 July 25th 03 01:00 AM


All times are GMT +1. The time now is 11:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"