Select Table and set WrapText to True

Raddle

New Member
Joined
Oct 24, 2023
Messages
41
Office Version
  1. 2016
Hi

Can anyone help with how to select all tables in a workbook and apply wraptext ?
I am guessing that wrap text is a cell property not a table property because when I add a like like tbl.wraptext=true it errors.

However who do I 'select' the table range and then apply this?

Hints very welcome.

Sub Acnt_FormatTableStyle() 'format the table
Dim tbl As ListObject
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets

For Each tbl In ws.ListObjects
Debug.Print tbl.name

tbl.TableStyle = "TableStyleMedium9"
tbl.ShowAutoFilterDropDown = False
Next tbl

Next ws
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try
VBA Code:
tbl.Range.WrapText = True
This will wrap text in everything--headers, data, and totals.

P.S. Don't Select the table.
 
Upvote 1
Solution
...doh!

It only needed

ActiveSheet.ListObjects(1).Range.Select

With Selection ' I had previously had '.interior' here which was stopping it from acting on the cells (I guess)


.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
.ShowAutoFilterDropDown = False
.WrapText = True

End With
 
Upvote 0
Selecting things to operate on them works, but it has a few drawbacks. It is almost always better to directly operate on the object, rather than Select it and operate on Selection.
 
Upvote 1
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Loop through excel tables turning on wrap text
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
let me also try this ...

Yep .. nailed it. Thank you so much 6StringJazzer ;)
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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