+ Reply to Thread
Results 1 to 4 of 4

VBA error

Hybrid View

fred2028 VBA error 05-01-2012, 07:04 PM
davesexcel Re: VBA error 05-01-2012, 08:27 PM
StevenM Re: VBA error 05-01-2012, 08:45 PM
fred2028 Re: VBA error 05-03-2012, 07:38 PM
  1. #1
    Registered User
    Join Date
    03-08-2011
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    28

    VBA error

    Hi,

    I am running a report and get this error

    Run-time error 1004: Application-defined or object-defined error

    Takes me to the line .Offset(i, 4).Value = .Offset(i, 3).Value - .Offset(i, 2).Value in my VBA function that is
    Public Sub GetMxVolume()
        Dim connstr As String
        Dim sqlStr As String
        Dim conn As connect
        Set conn = New connect
        
        Dim i As Integer
        Dim ticker As String
        Application.DisplayAlerts = False
        
        conn.connect_mx
                
        i = 1
        With Range("avgStart")
            Do While .Offset(i) <> ""
                ticker = .Offset(i).Value
                sqlStr = "select ISNULL(SUM(marketvolume),0) from mxmarketparticipation where ticker = '" & ticker & "'  " & _
                "and loaddate >= '" & startDate & "' and loaddate <= '" & endDate & "' and expirycutoff is null"
                conn.m_rds.Open sqlStr, conn.m_conn
                .Offset(i, 3).CopyFromRecordset conn.m_rds
                .Offset(i, 4).Value = .Offset(i, 3).Value - .Offset(i, 2).Value
                conn.m_rds.Close
                i = i + 1
            Loop
        End With
        
        
        
        
        
        
        Application.DisplayAlerts = True
            
    End Sub
    Firstly, how do I start debugging based off of that error? It seems super general. Secondly, how can you get an error from Offsets? Isn't it just moving around in the cells and subtracting?

    Where should I look for the source of the error? Thanks.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: VBA error

    Does that line of code get a value?

    What is the code supposed to do?
    Last edited by davesexcel; 05-01-2012 at 08:50 PM.

  3. #3
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: VBA error

    If the range
    With Range("avgStart")
    is a series of cells (as opposed to being a reference to one cell), then each offset:
    .Offset(i, 4).Value = .Offset(i, 3).Value - .Offset(i, 2).Value
    will be a range with the same number of rows and columns as the original Range("avgStart").

  4. #4
    Registered User
    Join Date
    03-08-2011
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: VBA error

    Hey Dave or steven, can I send you the excel sheet via email? I'd rather not post it publicly. If you want, you can email me fred2028@gmail.com so I can have your email. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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