+ Reply to Thread
Results 1 to 17 of 17

Pass Sheet name as argument to function

  1. #1
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Pass Sheet name as argument to function

    Hello Genius,
    I am working on user rights in excel sheet. It have around 78 sheets with 3 categories i.e. High Security, Moderate Security and Low security.
    I am using macros to switch between sheets. Each sheet can only be accessed by that macro assigned to a button.
    Now I am writing a function namely checkAccess(Worksheet name). It have a lot of if's and cases to grant access depending on the current user logged in. The function should take sheet name as input and check access on it. But I am unable to pass sheet name in function.
    By using this function I want to call this function in every switching macro and it will do everything else by itself.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Pass Sheet name as argument to function

    Assalamualaikum

    could you please provide sample workbook with desire output , how extactly your checking for access
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Pass Sheet name as argument to function

    Sounds as though you need
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Pass Sheet name as argument to function

    Quote Originally Posted by TMS View Post
    Sounds as though you need
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.

    Regards, TMS
    I will check it as soon as I reach home... Where should I put it? in macro like ?
    Please Login or Register  to view this content.

    Is it ok? I cant test right now.

  5. #5
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Pass Sheet name as argument to function

    Quote Originally Posted by Naveed Raza View Post
    Assalamualaikum

    could you please provide sample workbook with desire output , how extactly your checking for access
    Walaekum Assalam.
    Sure Naveed. I will provide my sample workbook. But Access program is not yet written . I will provide my algorithm for that. And will post my code as soon as it completes.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Pass Sheet name as argument to function

    I think it would look like this:

    Please Login or Register  to view this content.

    What screen updating is your code going to do?

    Regards, TMS

  7. #7
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Pass Sheet name as argument to function

    its nothing It is good if I keep switching b/w sheets. But that I think is not required now..

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Pass Sheet name as argument to function

    OK, fair enough ... didn't appear to be relevant in this instance.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pass Sheet name as argument to function

    Umair

    There is no way we can tell you how to pass the sheet name to the function without seeing the function you want to pass the sheet name to.
    If posting code please use code tags, see here.

  10. #10
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Pass Sheet name as argument to function

    Quote Originally Posted by Norie View Post
    Umair

    There is no way we can tell you how to pass the sheet name to the function without seeing the function you want to pass the sheet name to.
    sample security.xlsx
    Attached my file.
    My code for function is:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    There may b a few syntax mistake in my code. Its not written in excel. Its written in text editor.

  11. #11
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Pass Sheet name as argument to function

    Resolved.

    Please Login or Register  to view this content.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Pass Sheet name as argument to function

    Note that the brackets around the parameter(s) are not necessary.

  13. #13
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Pass Sheet name as argument to function

    Quote Originally Posted by TMS View Post
    Note that the brackets around the parameter(s) are not necessary.
    Thanks for the TIP TMS Please Add my reputation

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Pass Sheet name as argument to function

    Please Add my reputation
    I'm sorry; I don't understand. You add reputation by clicking on the little star at the bottom left of the post.

    Or are you expecting me to +rep you?

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pass Sheet name as argument to function

    Are you sure this is resolved?

    The function you posted in post #10 requires a worksheet object passed to it, not a worksheet name.

  16. #16
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Pass Sheet name as argument to function

    Quote Originally Posted by TMS View Post
    I'm sorry; I don't understand. You add reputation by clicking on the little star at the bottom left of the post.

    Or are you expecting me to +rep you?
    Hehehehe If you want you can Just kidding

  17. #17
    Registered User
    Join Date
    10-02-2012
    Location
    karachi
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Pass Sheet name as argument to function

    Quote Originally Posted by Norie View Post
    Are you sure this is resolved?

    The function you posted in post #10 requires a worksheet object passed to it, not a worksheet name.
    Yes Norie. I solved the problem myself. POst11 is what i wanted to do. just changed argument to string.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA Argument pass to DLL Issue
    By DougD720 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-27-2014, 09:11 PM
  2. Pass argument to SetSourceData
    By khdani in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 10-22-2008, 07:54 AM
  3. [SOLVED] Pass function as argument to UDF
    By Ron Rosenfeld in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-09-2006, 08:55 AM
  4. Pass Argument?
    By Hal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2005, 01:20 PM
  5. [SOLVED] Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1