+ Reply to Thread
Results 1 to 7 of 7

Problems getting a column width changed in multiple sheets at the same time.

  1. #1
    Registered User
    Join Date
    12-09-2015
    Location
    england
    MS-Off Ver
    2003
    Posts
    33

    Problems getting a column width changed in multiple sheets at the same time.

    I have tried the following to change column "BL" in multiple sheets at the same time and it is the only thing that doesn't seem to happen. Every other action in the macro performs correctly except the column width. It appears to change Period 1 but then leaves the rest alone. Where am I going wrong? p.s no error comes up.

    Sub unprotect_all_2()

    For Each wsheet In Worksheets
    wsheet.Unprotect
    Next wsheet

    Sheets(Array("Period 1", "Period 2", "Period 3", "Period 4", "Period 5", "Period 6", _
    "Period 7", "Period 8", "Period 9", "Period 10", "Period 11", "Period 12", _
    "Additional Checks")).Select

    Range("BL2").Select

    ActiveCell.FormulaR1C1 = "Has the appropriate contact been made and is the content of any correspondence sent clear and accurate whilst covering all relevant points/answering all questions (inc. spelling/grammar)"
    Range("bw5").Select
    ActiveCell.FormulaR1C1 = "Safeguarding"
    Range("BW2").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("BX2").Select
    ActiveCell.FormulaR1C1 = "2"
    Range("BY2").Select
    ActiveCell.FormulaR1C1 = "3"
    Range("BZ2").Select
    ActiveCell.FormulaR1C1 = "4"
    Range("CA2").Select
    ActiveCell.FormulaR1C1 = "5"

    Sheets(Array("Period 1", "Period 2", "Period 3", "Period 4", "Period 5", "Period 6", _
    "Period 7", "Period 8", "Period 9", "Period 10", "Period 11", "Period 12", _
    "Additional Checks")).Select
    Sheets("period 1").activate
    columns("bl:bl").columnwidth = 14.86

    Sheets("Year to date").Select
    Range("AA3").Value = "Safeguarding"
    For Each wsheet In Worksheets
    wsheet.Protect
    Next wsheet

    End Sub

    In the end and in order to get it to work I've had to resort to the following script. Can anyone tell me what I'm doing wrong in the first script?

    Sub unprotect_all()
    For Each wsheet In Worksheets
    wsheet.Unprotect
    Next wsheet
    Sheets(Array("Period 1", "Period 2", "Period 3", "Period 4", "Period 5", "Period 6", _
    "Period 7", "Period 8", "Period 9", "Period 10", "Period 11", "Period 12", _
    "Additional Checks")).Select

    Range("BL2").Select

    ActiveCell.FormulaR1C1 = "Has the appropriate contact been made and is the content of any correspondence sent clear and accurate whilst covering all relevant points/answering all questions (inc. spelling/grammar)"
    Range("bw5").Select
    ActiveCell.FormulaR1C1 = "Safeguarding"
    Range("BW2").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("BX2").Select
    ActiveCell.FormulaR1C1 = "2"
    Range("BY2").Select
    ActiveCell.FormulaR1C1 = "3"
    Range("BZ2").Select
    ActiveCell.FormulaR1C1 = "4"
    Range("CA2").Select
    ActiveCell.FormulaR1C1 = "5"

    Sheets("period 1").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 2").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 3").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 4").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 5").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 6").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 7").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 8").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 9").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 10").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 11").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("period 12").Select
    Columns("bl:bl").ColumnWidth = 14.86
    Sheets("additional checks").Select
    Columns("bl:bl").ColumnWidth = 14.86


    Sheets("Year to date").Select
    Range("AA3").Value = "Safeguarding"
    For Each wsheet In Worksheets
    wsheet.Protect
    Next wsheet

    End Sub

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Problems getting a column width changed in multiple sheets at the same time.

    It might be because there isn't a Next wsheet immediately after
    Please Login or Register  to view this content.
    Its after the wsheet.protect so it is only lopping the protect part of the code.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    12-09-2015
    Location
    england
    MS-Off Ver
    2003
    Posts
    33

    Re: Problems getting a column width changed in multiple sheets at the same time.

    Hi,

    No unfortunately that has not solved it. on a stand alone fix that came up with an error so I added in the following and still the same result, column width only changed in the "period 1" sheet.

    Sheets(Array("Period 1", "Period 2", "Period 3", "Period 4", "Period 5", "Period 6", _
    "Period 7", "Period 8", "Period 9", "Period 10", "Period 11", "Period 12", _
    "Additional Checks")).Select
    For Each wsheet In Selection
    Sheets("period 1").Activate
    Columns("bl:bl").ColumnWidth = 14.86
    Next wsheet

  4. #4
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: Problems getting a column width changed in multiple sheets at the same time.

    I checked your code against a wee test I did with the macro recorder. It looks pretty good except you have all of this:
    Please Login or Register  to view this content.
    repeated after you fill the cell values and before the columnwidth change but there is no need for it to be there, that was already done at the top of the code. This might be throwing things off maybe. If that's not it, I don't know what else it could be because it looks pretty good otherwise.

    That said, I generally wouldn't use .select or .activate if there's another way. They can really slow down your code.

    If you're up for a suggestion, the following code won't get "...a column width changed in multiple sheets at the same time", but it will achieve the same end result in a simple way by just looping through the sheets once and applying the columnwidth and the other changes to each sheet one after another. Your code loops through the sheets twice at the moment as it is. Oh, and there's no .select or .activate so it'll be quick too.

    Please Login or Register  to view this content.
    Last edited by kadeo; 05-20-2016 at 10:59 AM.
    Please click *Add Reputation if I've helped

  5. #5
    Registered User
    Join Date
    12-09-2015
    Location
    england
    MS-Off Ver
    2003
    Posts
    33

    Re: Problems getting a column width changed in multiple sheets at the same time.

    Thanks for the info kadeo, I'll give it a try!

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Problems getting a column width changed in multiple sheets at the same time.

    Another FWIW:

    Please Login or Register  to view this content.
    The problem with the first code is in the red. On each sheet you still reactivate Sheet Period 1 to do the Column Width adjustment. Therefore it doesn't affect the other sheets in the Array.

    Please Login or Register  to view this content.

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Problems getting a column width changed in multiple sheets at the same time.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy/Paste problems - Column/Row Height/Width changing
    By dlevisay in forum Excel General
    Replies: 1
    Last Post: 10-29-2014, 11:49 AM
  2. Macro for fixed column width and row height across multiple sheets
    By westbay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-09-2011, 03:15 AM
  3. Column width changed by user
    By excelbobabc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2010, 02:13 PM
  4. Adjusting column width for multiple sheets
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2009, 11:41 AM
  5. Standard Column Width on Multiple Sheets
    By walkingthecow in forum Excel General
    Replies: 1
    Last Post: 05-27-2008, 11:38 AM
  6. Column width Problems 2007
    By cooterjr in forum Excel General
    Replies: 1
    Last Post: 01-14-2007, 02:15 PM
  7. Changed column width keeps reverting back to original size
    By David Boone in forum Excel General
    Replies: 3
    Last Post: 05-29-2005, 09:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1