+ Reply to Thread
Results 1 to 16 of 16

Run-time error '1004: Method 'range' of object'_Global' failed

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Run-time error '1004: Method 'range' of object'_Global' failed

    Hi,

    I am getting this "Run-time error '1004: Method 'range' of object'_Global' failed" for the below code.Please advise.
    Sub LastRow(control As IRibbonControl)
    Dim LastCol As Variant
    Set LastCol = Range("XFD" & ActiveCell.Row).End(xlToLeft)
        
        Application.GoTo Range(ActiveCell, LastCol)
    End Sub
    Thanks in advance!

  2. #2
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    you've set your variable as a 'variant' data type, try range instead.

  3. #3
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    I have changed to Range but still getting same error.
    Getting this error mainly this type of file "Microsoft Office Excel 97-2003 Worksheet"

    Thanks!

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    You can not set to non VBA object.
    I think LastCol is a long variable, not an object, so remove set

    Set LastCol = Range("XFD" & ActiveCell.Row).End(xlToLeft)
    Dim LastCol As long
     LastCol = Range("XFD" & ActiveCell.Row).End(xlToLeft)

  5. #5
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    If I remove set and put the above code,getting same error for this line:
    Application.Goto Range(ActiveCell, LastCol)
    Thanks!

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    What are you trying to do?
    I do not like go to and will avoid using it if I can.

  7. #7
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    If I remove go to what I have to use instead?

    Thanks!

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    Only if I knew what are you trying to do.

  9. #9
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    I am trying to select active cell to last used cell in a row.

    Thank!

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    I do not think you can use an active cell as cells address.

    Sub test()
    
    Dim LastCol As Long
     LastCol = Range("XFD" & ActiveCell.Row).End(xlToLeft)
    
     Range("A1" & LastCol).Select
    
    End Sub

  11. #11
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    Make clear what you want the result to be.....

    This one selects the active cell until the last cell in that row
    Sub LastRow()
    Dim LastCol As Integer
    With ActiveSheet
        LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    End With
    Range(ActiveCell.Address, Cells(ActiveCell.Row, LastCol)).Select
    End Sub

  12. #12
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    This code is working only for first row.
    If I want to select any other rows it is not working.

    Thanks!

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    This one works too, but avoid active cell again.

    Sub test1()
    
    Dim LastCol As Long
     LastCol = Range("XFD" & ActiveCell.Row).End(xlToLeft)
     Range(ActiveCell.Address & LastCol).Select
    
    End Sub

  14. #14
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    Thanks for now let you know if I have any problem.

  15. #15
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    For selection of selected cell (on any row) to last cell used in the row:
    Sub LastRow()
    Dim LastCol, actRow As Integer
        With ActiveSheet
            actRow = ActiveCell.Row
            LastCol = .Cells(actRow, .Columns.Count).End(xlToLeft).Column
        End With
        Range(ActiveCell.Address, Cells(ActiveCell.Row, LastCol)).Select
    End Sub

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Run-time error '1004: Method 'range' of object'_Global' failed

    In the version of Excel you mention the columns only go up to IV.
    Sub LastRow(control As IRibbonControl)
    Dim LastCol As Range
    
        With ActiveCell.Parent
            Set LastCol = .Cells(ActiveCell.Row, .Columns.Count).End(xlToLeft)
            Application.GoTo .Range(ActiveCell, LastCol)
         End With
    
    End Sub
    Last edited by Norie; 02-01-2014 at 06:03 AM.
    If posting code please use code tags, see here.

+ 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] Run-time error 1004 - Method 'Range' of object'_Global' failed
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2013, 03:33 PM
  2. Run-time error '1004'. Method 'Range' of object '_Global' failed
    By mjj347 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-24-2012, 11:09 AM
  3. Run-time error '1004': Method 'Range' of object '_Global' failed
    By claremount in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-26-2010, 08:01 AM
  4. Run time error 1004 - Method 'Range' of 'Object'_Global' failed
    By excelaspire0219 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-10-2009, 01:18 PM
  5. Run-time error '1004': Method 'Range' of object '_Global' failed
    By Neild in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-2006, 07:50 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