Consulting

Results 1 to 3 of 3

Thread: range of object failed xcel 2013

  1. #1
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    1
    Location

    range of object failed xcel 2013

    I have recopied my 2010 macros to 2013 and am getting the error above on this line
    StartDate = DataSheet.Range("startDate").Value

    help would be appreciated


    Sub GetData()
    Dim DataSheet As Worksheet
    Dim EndDate As Date
    Dim StartDate As Date
    Dim Symbol As String
    Dim qurl As String
    Dim nQuery As Name
    Dim LastRow As Integer
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.Calculation = xlCalculationAutomatic
    
    
    Sheets("Data").Cells.Clear
    Set DataSheet = ActiveSheet
    
    StartDate = DataSheet.Range("startDate").Value '<<<<<<<<<<<<<<<<<
    
    EndDate = DataSheet.Range("endDate").Value
    ' StartDate = DataSheet.Range("startDate").Value
    ' EndDate = DataSheet.Range("endDate").Value
    Symbol = DataSheet.Range("ticker").Value
    Sheets("Data").Range("a1").CurrentRegion.ClearContents
    Last edited by SamT; 09-03-2016 at 10:20 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
        Sheets("Data").Cells.Clear 
        Set DataSheet = ActiveSheet
    Doesn't the first line Activate Sheets "Data?" Doesn't that Clear all the Cells for DataSheet?

    Good Programming Practice dictates that we avoid the use of ActiveSheet whenever possible. Assign an explicit sheet to DataSheet.


    Are you sure that the Range Name is accurate? Pay careful attention to extra and trailing spaces.

    First put "Option Explicit" at the top of all your code pages, and make liberal use of the VBA Menu Debug >> Compile.

    In some Cell on the Worksheet, start a Formula, (Type the "=" character,) then Insert Name "startDate" and copy it from the formula bar.

    Then go back to the VBA editor and paste the copied name in place of the Range Name in the code.

    Alternately, on a blank sheet, Insert >> Name >> Paste List and copy all the names you need from that list into your code. With that list, if you Format the cells to align right, you will see any extra trailing spaces.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Not at all sure about this, but avoid the use of DataSheet, it's used in the object model as the grid of data you can add to a chart.
    Try changing it thoughout your code to DataSht.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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