+ Reply to Thread
Results 1 to 7 of 7

Variable in function code

  1. #1
    Registered User
    Join Date
    07-07-2011
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    18

    Thumbs up Variable in function code

    Hi experts,

    I want to used counta function in VBA, where workbook and worksheet will change.
    I would like to use variable in formula and answer should be store in another variable.


    Please Login or Register  to view this content.
    OR

    Please Login or Register  to view this content.
    can anyone guide me how to use variable in function and answer will store directly in another variable.
    Thanks in advance
    Last edited by sachin parab; 07-17-2014 at 02:34 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Variable in function code

    Hi,

    Untested but something like

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  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,366

    Re: Variable in function code

    Or this:

    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
    07-07-2011
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Variable in function code

    Dear TMS,

    Thanks for your quick response, but which used first code i.e.
    Please Login or Register  to view this content.
    it gives Compile error "Expected list separate or )",

    and in second code i.e.
    Please Login or Register  to view this content.
    it give error Run-time error '9' subscript out of range

    so can you explain where I did wrong.
    Thanks for your help

  5. #5
    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,366

    Re: Variable in function code

    Did you change the workbook name and worksheet name? Is the workbook open? Does the sheet exist.

    The first code was yours to show what I was trying to match.

    Regards, TMS

  6. #6
    Registered User
    Join Date
    07-07-2011
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Variable in function code

    TMS thanks.
    It got resolved, thanks again for your support.

  7. #7
    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,366

    Re: Variable in function code

    You're welcome.



    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.

+ 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 Code for NPV Function with Variable interest rate
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-05-2014, 03:19 AM
  2. [SOLVED] Error in a Code. Object variable or With block variable not set????
    By ciapul12 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-03-2014, 12:20 PM
  3. [SOLVED] Excel VBA error code 91: Object variable or with block variable not set
    By wilnexpc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2013, 11:46 AM
  4. [SOLVED] Store variable in worksheet and use that variable in VBA code
    By ExcelGal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2012, 08:20 AM
  5. Error Code 91 Object Variable or With Block variable Not Set
    By florencia in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-30-2008, 04:46 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