+ Reply to Thread
Results 1 to 4 of 4

Error - Method 'range of object' - Global failed

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-13-2011
    Location
    Havant, Hants, England
    MS-Off Ver
    Excel 2010
    Posts
    116

    Error - Method 'range of object' - Global failed

    Hi all, I get the following error "Method 'range of object' - Global failed" when I run the code below. It's the Set objButton line that causes the problem. Can anybody explain what I need to do to fix it from going into error? thanks, Neil

    Private Sub AddButtons()
     
        Dim objButton As OLEObject
        Dim wsd As Worksheet
        Dim finalrow As Single
          
        Set wsd = Worksheets("MainData")   'Select worksheet
        finalrow = wsd.Cells(Application.Rows.Count, 1).End(xlUp).row   'Find final row
        
        CalcRowHeight    'Call procedure to calculate position to place button
        
        'Add button
        Set objButton = wsd.OLEObjects.Add _
        (ClassType:="Forms.CommandButton.1", Link:=False _
        , DisplayAsIcon:=False, Left:=1000, Top:=strTop, Width:=153, Height:=80)
        
        'Assign propeties to button
        With objButton
            .Name = "Adjust_Main_Data"
            .Object.Caption = "Adjust Main Data"
            .Object.FontSize = 14
            .Object.FontName = "Verdana"
            .Object.Font.Bold = True
            .Object.ForeColor = vbBlack
            .Object.BackColor = vbRed
            'Set ThisWorkbook.CommandButtonEvent = objButton.Object
        End With
            
        Range("C2:" & StrRowNo).Select
        Selection.NumberFormat = "0"    'Format column for number to enable show code report
     End Sub

  2. #2
    Forum Contributor LokeshKumar's Avatar
    Join Date
    03-31-2015
    Location
    India
    MS-Off Ver
    All, mostly 2010 now..
    Posts
    471

    Re: Error - Method 'range of object' - Global failed

    hey
    this is not correct replace it with correct code.....
    what is StrRowNo
    Range("C2:" & StrRowNo).Select
    Lokesh Kumar
    Stay Hungry.. Stay Foolish..
    _________________________________________________________
    Please Click STAR to Add Reputation if my/someone's answer helped!

  3. #3
    Forum Contributor
    Join Date
    04-13-2011
    Location
    Havant, Hants, England
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Error - Method 'range of object' - Global failed

    Hi, thanks for the reply. When you say "this is not correct replace it with correct code....." - that's what I'm asking the help for!

    StrRowNo is a variable I generate in a previous routine - it can be ignored as it is not anything to do with the error,

    regards, Neil

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,291

    Re: Error - Method 'range of object' - Global failed

    It has to be the error - it's the only place you use Range calls. What is the actual value of strRowNo? If it's a row number, your code should be:
    Range("C2:C" & StrRowNo).Select
    Remember what the dormouse said
    Feed your head

+ 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. method union of object global failed error
    By evanzo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-29-2013, 11:07 PM
  2. Method 'Cells of Object' Global failed error
    By TimmerSuds in forum Excel General
    Replies: 2
    Last Post: 05-20-2012, 09:29 AM
  3. 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
  4. 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
  5. 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