+ Reply to Thread
Results 1 to 2 of 2

Method 'Range' of Object'_Global' Failed Error

Hybrid View

  1. #1
    Registered User
    Join Date
    10-08-2014
    Location
    Blacksburg, Virginia
    MS-Off Ver
    2013
    Posts
    18

    Method 'Range' of Object'_Global' Failed Error

    I can't figure out why I am getting this error or how to correct it, any thoughts? TThe error is occuring in the line:
    If Range("PaymentAmount").Offset(i, 0) = "Cash" Then
    Sub Calculation()
        Dim r As Range, CashAvg As Double, CheckAvg As Double, CreditAvg As Double
        Dim CashSum As Double, CashCount As Integer, CheckSum As Double, CheckCount As Integer, CreditSum As Double, CreditCount As Integer
    
        Set r = Range(Range("I2"), Range("I2").End(xlDown))
        
        
    With ThisWorkbook.Worksheets("Problem3")
        For i = 1 To r.Rows.Count
            If Range("PaymentAmount").Offset(i, 0) = "Cash" Then
                CashSum = CashSum + Range("I").Offset(i, 1)
                CashCount = CashCount + 1
            ElseIf Range("I").Offset(i, 0) = "Check" Then
                CheckSum = CheckSum + Range("I").Offset(i, 1)
                CheckCount = CheckCount + 1
            ElseIf Range("I").Offset(i, 0) = "Credit" Then
                CreditSum = CreditSum + Range("I").Offset(i, 1)
                CreditCount = CreditCount + 1
            End If
        Next i
    End With
        
        If CashSum > 0 And CashCount > 0 Then
            CashAvg = CashSum / CashCount
        Else
            CashAvg = 0
        End If
        If CheckSum > 0 And CheckCount > 0 Then
            CheckAvg = CheckSum / CheckCount
        Else
            CashAvg = 0
        End If
        If CreditSum > 0 And CreditCount > 0 Then
            CreditAvg = CreditSum / CreditCount
        Else
            CreditAvg = 0
        End If
        MsgBox "CashAvg = " & CashAvg & "   CheckAvg = " & CheckAvg & "   CreditAvg = " & CreditAvg
            
    End Sub

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Method 'Range' of Object'_Global' Failed Error

    First thought is that you spelled something wrong and that either the sheet Problem3 does not exist or the named range PaymentAmount does not exist on the sheet Problem3. Double check for leading and trailing spaces as they matter.

    Edit:
    Here, run this code as a separate subroutine. It should tell you if what I think is correct.

    Sub Test_for_Range()
    Dim SheetName As String, NamedRange As String
    
    ''''''''''''''''''''''''''''''''''''''''''''''''
    '
    '  Enter the sheet name and named range you want
    '  to test for:
    
       SheetName = "Problem3"
       NamedRange = "PaymentAmount"
    
    '
    ''''''''''''''''''''''''''''''''''''''''''''''''
    
    Dim ws As Worksheet:    Set ws = Nothing
    Dim rng As Range:   Set rng = Nothing
    Dim str As String
    
    On Error Resume Next
    Set ws = Sheets(SheetName)
    Set rng = Sheets(SheetName).Range(NamedRange)
    
    If Not ws Is Nothing And Not rng Is Nothing Then
        str = "The worksheet: " & SheetName & " exists." & vbCr _
                & "The named range: " & NamedRange & " exists."
    ElseIf Not ws Is Nothing And rng Is Nothing Then
        str = "The worksheet: " & SheetName & " exists." & vbCr _
                & "The named range: " & NamedRange & " does not exist."
    Else
        str = "The worksheet " & SheetName & " does not exist. Correct it and rerun code to verify the named range."
    End If
    On Error GoTo 0
    
    MsgBox str
    
    End Sub
    Last edited by stnkynts; 10-13-2014 at 07:32 PM.

+ 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] Getting error Method 'Range' of object '_Global' failed
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2013, 04:35 PM
  2. VBA Method 'Range' of object '_Global' failed error
    By RxMiller in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2011, 11:06 AM
  3. Error: Method 'Range' of object '_Global' failed
    By awan0126 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2011, 07:25 PM
  4. VBA Method 'Range' of object '_Global' failed error
    By JKCincy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-21-2009, 07:46 PM
  5. Method 'Range' of object' _Global failed error
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-12-2009, 01:52 AM

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