![]() |
Set column widths to match specified sheet
Hi,
I am would like to write some code to set the column width of all selected worksheets to match the column widths in a specified sheet. Does anyone know of any existing code or an add-in (free) that does this? I often use multipage workbooks and can easily set the columns on all sheets to be the same on all sheets by selecting all sheets and changing the column width. Problems arise when the columns are later changed and I find myself forever resetting the column widths. Any assistance would be appreciated. Regards. Sean |
Set column widths to match specified sheet
Good morning Sean Bartleet I have a free add-in available to anyone requesting it which wil (amongst other things) copy and paste cell widths across files. If yo would like this please send me an e-mail. HTH DominicB -- dominic ----------------------------------------------------------------------- dominicb's Profile: http://www.excelforum.com/member.php...fo&userid=1893 View this thread: http://www.excelforum.com/showthread.php?threadid=48461 |
Set column widths to match specified sheet
Hello Sean, Dominic kindly offered you his Add-in in reponse to one part of your request. I am offering the you the code portion in response to the second half of your request. This macro will ask you if you want to apply the active sheet's column widths to the other sheets in the workbook. If the answer is No, it does nothing. Insert a VBA module into your project and copy this code into. You can run the macro from the Macro List (use ALT + F8 to bring up the list). Code: -------------------- Public Sub SetColumnWidths() Dim Answer, Col, Sht Dim MasterRng As Range Dim MasterSht As String Dim Msg As String Msg = "Do you want to apply this Worksheet's" & vbCrLf _ & "Column Widths to all the Worksheets?" Answer = MsgBox(Msg, vbInformation + vbYesNo) If Answer = vbNo Then Exit Sub MasterSht = ActiveSheet.Name Set MasterRng = ActiveSheet.Range("A1", "IV1") For Each Sht In Worksheets If Sht.Name < MasterSht Then For Each Col In MasterRng Sht.Range(Col.Address).ColumnWidth = Col.ColumnWidth Next Col End If Next Sht End Sub -------------------- Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=484619 |
Set column widths to match specified sheet
Leith, Thanks for the code.
Dominic, thanks for the add in, quite excellent. I really appreciate both. Sean "Leith Ross" wrote in message ... Hello Sean, Dominic kindly offered you his Add-in in reponse to one part of your request. I am offering the you the code portion in response to the second half of your request. This macro will ask you if you want to apply the active sheet's column widths to the other sheets in the workbook. If the answer is No, it does nothing. Insert a VBA module into your project and copy this code into. You can run the macro from the Macro List (use ALT + F8 to bring up the list). Code: -------------------- Public Sub SetColumnWidths() Dim Answer, Col, Sht Dim MasterRng As Range Dim MasterSht As String Dim Msg As String Msg = "Do you want to apply this Worksheet's" & vbCrLf _ & "Column Widths to all the Worksheets?" Answer = MsgBox(Msg, vbInformation + vbYesNo) If Answer = vbNo Then Exit Sub MasterSht = ActiveSheet.Name Set MasterRng = ActiveSheet.Range("A1", "IV1") For Each Sht In Worksheets If Sht.Name < MasterSht Then For Each Col In MasterRng Sht.Range(Col.Address).ColumnWidth = Col.ColumnWidth Next Col End If Next Sht End Sub -------------------- Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=484619 |
All times are GMT +1. The time now is 12:06 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com