Run time error 438 object doesnt support this property or method

vbacoder12

New Member
Joined
Sep 4, 2024
Messages
41
Office Version
  1. 2024
  2. Prefer Not To Say
Platform
  1. Windows
Hi ,
I cannot copy my code into the message at this time. I am going to type n i really apologize. When using code I get the error in the subject. Also it puts the table in a style which is not in the code. Debug highlights set tbl line. Which starts set tbl and ends at 21) if this is too hard to read it can upload image. If I can

Sub FormatATable()
Dim tbl As ListObject
Dim rng As Range
Set rng = Range("A6") Settbl=ActiveSheet.ListObjects.Add(xlSrcRange, Range("A6:Q9000"), , xlYes).Header = No.TableStyle=Green Table Style Medium 21)
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi vbacoder12,

Please provide a screenshot, also, you have a closing parenthesis after 21 but no openning one why?

Bests regards,

Vincent
 
Upvote 0
I can't find a Green 21 but this will give you the syntax:

VBA Code:
Sub FormatATable()
    Dim tbl As ListObject
    Dim rng As Range
    
    Set rng = Range("A6")
    Set tbl = ActiveSheet.ListObjects.Add(SourceType:=xlSrcRange, Source:=Range("A6:Q9000"), _
                                            XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium25")

End Sub
 
Upvote 0
Solution
I can't find a Green 21 but this will give you the syntax:

VBA Code:
Sub FormatATable()
    Dim tbl As ListObject
    Dim rng As Range
   
    Set rng = Range("A6")
    Set tbl = ActiveSheet.ListObjects.Add(SourceType:=xlSrcRange, Source:=Range("A6:Q9000"), _
                                            XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium25")

End Sub
This very useful. But what would I add if I wanted my first line of data to be headers. That would be row 6. Also how could I add borders around the cells
 
Upvote 0
That code specifies the range starting at row 6 and for Headers = xlYes, which makes row 6 the headings. Is that not working ?

If you want to add borders ideally you need to find a style that does what you want or copy and modify a style to suit. Then use the style name of the custom style in the code.
 
Upvote 0
That code specifies the range starting at row 6 and for Headers = xlYes, which makes row 6 the headings. Is that not working ?

If you want to add borders ideally you need to find a style that does what you want or copy and modify a style to suit. Then use the style name of the custom style in the code.
It added headers above row 6. My headers start at row 6 and data at row 7
 
Upvote 0
I put some data on Row 5 and it still did the right thing and put the header row on Row 6
Show me the exact code you are using and a screenshot of the sheet showing the row and column references.
 
Upvote 0
I put some data on Row 5 and it still did the right thing and put the header row on Row 6
Show me the exact code you are using and a screenshot of the sheet showing the row and column references.
Now I see where I made the mistake at i have data in row 6 (names for headers already). I just want to make that data in row 6 the headers
 
Upvote 0

Forum statistics

Threads
1,225,743
Messages
6,186,777
Members
453,370
Latest member
juliewar

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