object variable or with block variable not set

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,340
Office Version
  1. 365
Platform
  1. Windows
I have a button on the tab that runs this code. The refresh is for a table on the tab and the table starts in A5

Code:
Sub RefreshProp()
' RefreshIHS Macro
'
    Sheets("PROP_MASTER_TABLE").Select
     With Sheets("PROP_MASTER_TABLE")
        .Range("C1").Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
    End With
    
    Range("D6").Select
    Selection.ListObject.TableObject.Refresh
    
End Sub

Not sure what the error message means or how to fix the code
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
What does the error message say and for which line?
 
Upvote 0
What does the error message say and for which line?
The Line is:
Selection.ListObject.TableObject.Refresh


Run-time error '91': The message that pops up is "Object variable or with block variable not set"
 
Upvote 0
You need to set the objects first so something like this though the tableobject is not set to do anything.

VBA Code:
Sub RefreshProp()
' RefreshIHS Macro
'
Dim wrksht As Worksheet
Dim objTable As TableObject
 
Set wrksht = ActiveWorkbook.Worksheets("Sheet1")
Set oListCol = wrksht.ListObjects(1).ListRows
Set objTable = objWorksheet.ListObjects

    Sheets("Sheet1").Select
     With Sheets("Sheet1")
        .Range("C1").Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
    End With
    
    Range("D6").Select
    Selection.ListObject.TableObject.Refresh
objTable.Refresh
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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