• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Excel formatting: force lengthy, wrapping column headers to narrowest width possible while constraining height of the header row|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / Excel formatting: force lengthy, wrapping column headers to narrowest width possible while constraining height of the header row|General Excel Questions & Answers|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…Excel formatting: force lengthy, wr…
sp_PrintTopic sp_TopicIcon
Excel formatting: force lengthy, wrapping column headers to narrowest width possible while constraining height of the header row
Avatar
CR Jordan

New Member
Members
Level 0
Forum Posts: 2
Member Since:
October 21, 2020
sp_UserOfflineSmall Offline
1
October 21, 2020 - 7:08 am
sp_Permalink sp_Print

I regularly receive a series of simple (data only) Excel workbooks from a government entity. A typical worksheet includes several thousand records (in rows) with data spread across approximately 800 different fields (in columns). Other than basic cell borders and text-wrapping in the row that contains column headers, the workbooks arrive without any formatting; each column is set to a uniform width of 10.00 (65 pixels). Many of the column headers are extremely long in length and when text-wrapped in a 65-pixel-wide column, result in a very tall header row.

Upon receiving the data, I manually adjust column widths to force the header row to a shorter height, but a height which still keeps the full text of each column header in view. However, try not to make any single column wider than necessary... so it is not as simple as just forcing all columns to a very wide standard width. With 800+ columns with headers of varying lengths, this is an extremely time-consuming undertaking. I would like to find a way to automate this process.

Is there a way to automate this reformatting process? In other words, is there a way to limit the header row's height to a value I define and then have each column automatically adjust its width to the narrowest possible value that still enables the column's header to be completely visible (with wrapping) within the constraints of the defined header row height?

The attached worksheet is a scaled-down example of what I receive ('Sample Table 1'; cells B3:I8) and how I would like it to look after formatting ('Sample Table 2'; cells L14:S19). As you can see in Sample Table 2, columns P:S are as narrow as they can be so the column headers in row 14 are fully visible, but do not result in a height for row 14 that exceeds 38.25 (or three lines of wrapped text).

Any tips are greatly appreciated!

For reference, I am using Excel 2016 on a PC.

sp_AnswersTopicSeeAnswer See Answer
Avatar
Purfleet
England
Member
Members


Trusted Members
Level 4
Forum Posts: 412
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
2
October 21, 2020 - 5:13 pm
sp_Permalink sp_Print

Probably requires a bit more testing but you could put this in you personal macro workbook or in the template if you have one

Sub RowH()

Dim RowHeight As Integer
Dim RowNumber As Integer

RowHeight = InputBox("type in the max height of the row", "Row Height")
RowNumber = InputBox("What row number do you want to correct?", "Row Number")

ActiveSheet.Range(RowNumber & ":" & RowNumber).RowHeight = RowHeight
ActiveSheet.Range("a:xfd").ColumnWidth = 1
ActiveSheet.Columns.AutoFit

End Sub

sp_AnswersTopicAnswer
Answers Post
Avatar
CR Jordan

New Member
Members
Level 0
Forum Posts: 2
Member Since:
October 21, 2020
sp_UserOfflineSmall Offline
3
October 22, 2020 - 3:03 am
sp_Permalink sp_Print

Purfleet,

I used your suggested code and it worked perfectly! Thank you so much for taking the time to respond - it will save me HOURS of work in the future and I appreciate this very much.

Best,

CR Jordan

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Jessica Stewart, Mark Carlson, Calvin Richardson, Debi Morgan
Guest(s) 5
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Debi Morgan
yashal minahil
Oluwadamilola Ogun
Yannik H
dectator mang
Francis Drouillard
Orlando Inocente
Jovitha Clemence
Maloxat Axmatovna
Ricardo Freitas
Forum Stats:
Groups: 3
Forums: 24
Topics: 6201
Posts: 27185

 

Member Stats:
Guest Posters: 49
Members: 31861
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.