Consulting

Results 1 to 10 of 10

Thread: Solved: Sheet names in formulae

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Solved: Sheet names in formulae

    Mental blank time again?
    In cell D2 I have the formula =MAX('Sheet2'!K:K). If I enter "Sheet2" in cell B2, can I refer to B2 so that I can copy down to refer to each sheet?
    I can accomplish this with =MAX(INDIRECT(B2)) if I change B2 to Sheet2!K:K but for flexibility, would like to avoid this change.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =MAX("'"&INDIRECT(B2)&"'!K:K)
    Last edited by mdmackillop; 08-21-2006 at 10:09 AM. Reason: See revised formula below

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I knew it had to be in there somewhere,
    Thanks Bob
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    does it work? but when i copy the formula it contains an error.. it says "The formula you type contains an error."

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You are absolutely right, it should be

    =MAX(INDIRECT("'"&B2&"'!K:K"))

  6. #6
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    you know i'm trying to solve your formula but i'm so stupid i didn't even think that, maybe time will come..

  7. #7
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    And of course, the UDF ...

    http://vbaexpress.com/kb/getarticle.php?kb_id=213

    I'd still take the INDIRECT, but fwiw.

    And gnod, you're definitely not stupid. Bob is very good with this stuff and he just screwed up something very, very easy. We ALL do it.

  8. #8
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    thanks zack.. i'll do my best to participate in this forum..

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by firefytr
    ...and he just screwed up something very, very easy. We ALL do it.
    and I spent 10 minutes trying to get these **** apostrophes in the right place. Thanks for pointing it out.

    Zack,
    It's a real bad day here. I knew that there must be a simple solution, so the thought of creating a UDF never crossed my mind. Here it is for anyone who wants it.

    [vba]Function DoMax(Data As String, Col As Long)
    DoMax = Application.WorksheetFunction.Max(Worksheets(Data).Columns(Col))
    End Function
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by gnod
    thanks zack.. i'll do my best to participate in this forum..
    Hi Gnod,
    You missed a couple.

    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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