Method 'Range' of object'_Global' failed

joslaz

Board Regular
Joined
May 24, 2018
Messages
76
Hey!


I am using the following code, to jump to the first day of the month.
The buttons includes the name of the month ("Jan"...).


It works perfectly at my computer, but not on others.
There is always an error: Method 'Range' of object'_Global' failed on the "Set vRange = Range("TblOP[[#Headers],[" & vDate & "]]")"




Do you know why?


Code:
    Sub PrcCurrentMonth()
    
    Dim vNumber As Long
    Dim vDate As Date
    Dim vMonth As Variant
    Dim vRange As Range
    
    
    vMonth = ActiveSheet.Shapes(Application.Caller).DrawingObject.Caption
    vNumber = WorksheetFunction.Match(vMonth, Application.GetCustomListContents(7), 0)
    vDate = DateSerial(2019, vNumber, 1)
    
    Set vRange = Range("TblOP[[#Headers],[" & vDate & "]]")
    
        If Not vRange Is Nothing Then
            Application.Goto vRange, True
            Set vRange = Nothing
    
        End If
    
    End Sub
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I tried googling what TblOP would mean, here on my office desktop. Guess I won't be doing that anymore...
NSFW
 
Upvote 0
What headers do you have in the table TblOP?
 
Upvote 0
Either the Table name or header is not being found by VBA

Is the Table name being found?
("Subscript out of Range Error" returned if table not found - check table name)
add these 2 lines as first 2 lines of code
Code:
    MsgBox 1 & vbCr & ActiveSheet.ListObjects("TblOP").Name
    exit sub

If Table is found, then the header is not being found
Is the header being found?
add these lines immediately below vDate = DateSerial(2019, vNumber, 1)
Code:
   On Error Resume Next
   Dim r As String: r = ActiveSheet.ListObjects("TblOP").HeaderRowRange.Find(vDate, lookat:=xlWhole).Address
   If r = "" Then MsgBox "Not Found" Else MsgBox "found at " & r
 
Last edited:
Upvote 0
If you want to find a header in the table why not use ListColumns.Range?
Code:
 Set vRange = ActiveSheet.ListObjects("TblOP").ListColumns(vDate).Range.Cells(1,1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top