+ Reply to Thread
Results 1 to 13 of 13

Runtime error 1004 Method 'Range' of object_ Global Failed

Hybrid View

stevoDE Runtime error 1004 Method... 06-29-2017, 11:40 AM
Special-K Re: Runtime error 1004 Method... 06-29-2017, 11:43 AM
xladept Re: Runtime error 1004 Method... 06-29-2017, 11:46 AM
stevoDE Re: Runtime error 1004 Method... 06-29-2017, 11:53 AM
Special-K Re: Runtime error 1004 Method... 06-29-2017, 11:46 AM
xlnitwit Re: Runtime error 1004 Method... 06-29-2017, 11:46 AM
xladept Re: Runtime error 1004 Method... 06-29-2017, 11:59 AM
stevoDE Re: Runtime error 1004 Method... 06-29-2017, 12:21 PM
xladept Re: Runtime error 1004 Method... 06-29-2017, 11:51 AM
xladept Re: Runtime error 1004 Method... 06-29-2017, 12:37 PM
stevoDE Re: Runtime error 1004 Method... 06-30-2017, 04:41 AM
stevoDE Re: Runtime error 1004 Method... 06-30-2017, 06:22 AM
xladept Re: Runtime error 1004 Method... 06-30-2017, 11:33 AM
  1. #1
    Forum Contributor
    Join Date
    04-11-2017
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2010
    Posts
    110

    Runtime error 1004 Method 'Range' of object_ Global Failed

    Can someone please tell me why this code is failing?

    Sub test()
    
    Dim LastRow As Long
    Dim rng As Range
    Dim i As Long
    
    LastRow = Cells(Rows.Count, "B").End(xlUp).Offset(-2, 0).Row
    
    Set rng = Range("B8:B" & LastRow).Resize(, 7)
     
         With rng
                For i = 1 To .Rows.Count
                    If .Cells(i, 7).Value <> "" Then
                        Range(i, 7).Resize(0, -7).Copy
                    End If
                Next i
           End With
    End Sub
    *edit* I = 1 to .rows.count and not 8
    Last edited by stevoDE; 06-29-2017 at 11:48 AM.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,077

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Please ignore this reply.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    You can't resize <1 and you can't offset -2 from the second column; is what immediately "pops out"
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Contributor
    Join Date
    04-11-2017
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2010
    Posts
    110

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Quote Originally Posted by xladept View Post
    You can't resize <1 and you can't offset -2 from the second column; is what immediately "pops out"
    I'm offsetting -2 rows from the last used row starting from the bottom, not from the second column. I'm not sure what you mean about resize <1.

    I have edited my code as 'i' should have been 1. I'm basically trying to check if the value in column H is blank. If it is not, I want to copy that row from column B to H i.e. H resized by -7 columns.

  5. #5
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,077

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Darn, I wish I'd kept my reply now

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Hi,

    You need Cells, not Range if you want to pass a row and column argument like that, and the size and offset are wrong.

    Did you mean to start your loop from B15?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    For i = 1 To LastRow
                    If .Cells(i, 7).Value <> "" Then
                        .Cells(i, 1).Resize(1,7).Copy
                    End If
                Next i
    ????


    I was wrong about the column offset as it's, obviously, a row offset.

    Offset and resize do not work the same way, Resize(0,-7) is

    defining a zero rows and negative 7 columns - it can never was:|
    Last edited by xladept; 06-29-2017 at 12:03 PM.

  8. #8
    Forum Contributor
    Join Date
    04-11-2017
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2010
    Posts
    110

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Quote Originally Posted by xladept View Post
    For i = 1 To LastRow
                    If .Cells(i, 7).Value <> "" Then
                        .Cells(i, 1).Resize(1,7).Copy
                    End If
                Next i
    ????


    I was wrong about the column offset as it's, obviously, a row offset.

    Offset and resize do not work the same way, Resize(0,-7) is

    defining a zero rows and negative 7 columns - it can never was:|
    With you now, I wasn't aware you couldn't resize to the left.

    The above doesn't seem to do what I'm after and that's probably because I didn't mention that I want to copy all rows (equivalent of holding down the CTRL key and copying). The above code only copies the last row where the value in column H is not blank.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    @ Special-K You can reinstate your reply - we won't care and we'd like to see it

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Try this:

    Sub stevoDEAuto()
    
    Dim LastRow As Long
    Dim rng As Range
    
    LastRow = Cells(Rows.Count, "B").End(xlUp).Offset(-2, 0).Row
    
    Set rng = Range("B8:B" & LastRow).Resize(, 7)
    rng.AutoFilter Field:=7, Criteria1:="<>"
    rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy
    rng.AutoFilter
    End Sub

  11. #11
    Forum Contributor
    Join Date
    04-11-2017
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2010
    Posts
    110

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Please ignore.
    Last edited by stevoDE; 06-30-2017 at 06:20 AM.

  12. #12
    Forum Contributor
    Join Date
    04-11-2017
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2010
    Posts
    110

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Quote Originally Posted by xladept View Post
    Try this:

    Sub stevoDEAuto()
    
    Dim LastRow As Long
    Dim rng As Range
    
    LastRow = Cells(Rows.Count, "B").End(xlUp).Offset(-2, 0).Row
    
    Set rng = Range("B8:B" & LastRow).Resize(, 7)
    rng.AutoFilter Field:=7, Criteria1:="<>"
    rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy
    rng.AutoFilter
    End Sub
    This works. I was looking to only copy the columns (i.e. B:H) within my specified range as opposed to the entire row but I managed to fix that myself.

    Thanks!

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Runtime error 1004 Method 'Range' of object_ Global Failed

    Try:


    rng.SpecialCells(xlCellTypeVisible).Resize(,7).Copy

+ 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. runtime error 1004 range of object global failed excel 2010
    By kwesmc1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2014, 05:22 PM
  2. [SOLVED] Runtime Error '1004' Method 'Range' of object '_Worksheet' failed
    By ovalstar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2013, 02:15 PM
  3. [SOLVED] Runtime error 1004: Method 'Range' of object '_Worksheet' failed
    By Phil Payne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2013, 01:30 AM
  4. Method 'Range' of object_ 'Global' Failed
    By naveenmarapaka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-12-2012, 10:35 AM
  5. Run-time error '1004': Method 'Range' of object 'Global' failed
    By djwestholm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2012, 04:52 PM
  6. Run-time error '1004': Method 'Range' of object '_ Global' failed
    By mdvc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-20-2011, 11:48 AM
  7. 1004:runtime error method 'range' of object'_Global failed
    By trksbc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-21-2009, 03:25 AM
  8. runtime error 1004 method range of object global failed
    By dreamz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2006, 03:25 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