+ Reply to Thread
Results 1 to 3 of 3

script to selecting correct sheet calculated via cell formula

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    script to selecting correct sheet calculated via cell formula

    I am having a few problems with this script:

    Sub Reporting()
    Dim wbname As String
    Dim SName As String
        wbname = Range("D5").Value
        SName = Range("D7").Value
        
    Workbooks.Open Filename:=wbname
    
    With Sheets(SName)
        .Activate
    End With
    
    Call IMPORT
    Call PILOT_STATS_UPDATE
    Call BANDING_UPDATE
    Call VP_UPDATE
    Call TIDY_UP
    'Call CLOSE_THIS_WB
    
    End Sub
    cell D5 contains the formula: ="S:\Contact Centre Analyst\Adams\Tiger Data\Tiger Data - "&TEXT(MONTH(WORKDAY(TODAY(),-1))*29,"MMM")&" "&YEAR(WORKDAY(TODAY(),-1))&".xls"

    D7 - =DAY(WORKDAY(TODAY(),-1))

    When I step through the code step by step it works perfectly, but unfortunately when I run it normally, it doesn't appear to select the correct sheet. I'm thinking its because the references are calculated within the cell rather than the code itself (not entirely sure if this actually makes a difference or not).

    Does anyone have a suggestion or two to resolve this?

  2. #2
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Re: script to selecting correct sheet calculated via cell formula

    I'm now getting an error of "Run Time Error 9 - subscript out of range at the step:

    With sheets(SName) <=== this is highlighted yello
    .activate
    End With
    SName shout resolve to 16 in this particular instance which is both the NAME of the sheet as well as its CODENAME, I want to be sure to be referencing its name however, but have stared so long at this i'm tying myself in knots and getting rather confused.
    Last edited by Kramxel; 07-17-2013 at 06:20 AM.

  3. #3
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Re: script to selecting correct sheet calculated via cell formula

    I've uploaded the entire file i'm working with, hoping this will help.
    Attached Files Attached Files

+ 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. [SOLVED] No calling correct script
    By floydian in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2013, 05:14 AM
  2. Replies: 0
    Last Post: 10-26-2012, 12:07 PM
  3. Selecting correct cell after Autofilter
    By subtilty in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2011, 11:49 AM
  4. Locating and selecting a column with VB Script
    By bigtonyicu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2008, 02:17 PM
  5. [SOLVED] How do I get correct results when LOOKUP with calculated numbers
    By onthemountain in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-19-2006, 08:20 PM

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