Consulting

Results 1 to 7 of 7

Thread: Solved: Named cell reference

  1. #1
    VBAX Regular
    Joined
    Apr 2009
    Posts
    59
    Location

    Solved: Named cell reference

    Hello,

    I have named cells on my spreadsheet. These are named: vo_a, vo_b
    In my code, I have the following lines

    [VBA]If IsNumeric(Workbooks("Outlier").Sheets("Spreadsheet").range("vo_a")) Then
    vo_a = Workbooks("Outlier").Sheets("Spreadsheet").range("vo_a").Value
    End If
    If IsNumeric(Workbooks("Outlier").Sheets("Spreadsheet").range("vo_b")) Then
    vo_b = Workbooks("Outlier").Sheets("Spreadsheet").range("vo_b").Value
    End If[/VBA]



    These both give me: "Subscript out of range errors". The workbook and sheet names are definitely right.I have other named cells creating the same error.
    What really puzzles me is that is was working fine 2 weeks ago when i last opened the workbook.
    Any ideas? Thanks!!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not without seeing the workbook, no.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You're missing .xls in your workbook name.
    You coud simplify with
    [VBA]
    Dim tmp as Variant
    tmp = Workbooks("Outlier.xls").Sheets("Spreadsheet").Range("vo_a").Value
    If IsNumeric(tmp) Then vo_a = tmp

    [/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'

  4. #4
    VBAX Regular
    Joined
    Apr 2009
    Posts
    59
    Location
    I actually noticed, through messing with it a bit that the error is coming from somewhere else, since the line
    [VBA]Call check(Workbooks("Outlier").Sheets("Spreadsheet").range("A30:A600"), 5)[/VBA]

    Gives the same error.
    Is it possible that it is not finding my workbook because of some directory location issue?

  5. #5
    VBAX Regular
    Joined
    Apr 2009
    Posts
    59
    Location
    Quote Originally Posted by mdmackillop
    You're missing .xls in your workbook name.
    You coud simplify with
    [vba]
    Dim tmp as Variant
    tmp = Workbooks("Outlier.xls").Sheets("Spreadsheet").Range("vo_a").Value
    If IsNumeric(tmp) Then vo_a = tmp

    [/vba]
    Yes, putting ".xlsm" solves the error! Thanks!!
    Puzzling though why it worked beforehand...

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    It would work with "Book1" as an unsaved workbook.
    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'

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Named Ranges do not need to be fully qualified. In my testing, doing so will cause an error unless the parent sheet of the named range is active.
    [VBA]If IsNumeric(Range("vo_a")) Then
    vo_a = Range("vo_a").Value
    End If
    If IsNumeric(Range("vo_b")) Then
    vo_b = Range("vo_b").Value
    End If [/VBA]

Posting Permissions

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