Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 24

Thread: Solved: Zoom and Setting Column Sizes

  1. #1

    Solved: Zoom and Setting Column Sizes

    Hi,

    I have this code which zooms all my sheets to 75% but i'm unable to get it set column sizes, can someone tell me what i'm doing wrong.

    Sub MyMacro12()
    
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    
    For Each ws In ActiveWorkbook.Worksheets
      ws.Activate
     
         ActiveWindow.Zoom = 75
       
    'ActiveWindow("A:A").EntireColumn.AutoFit  
     'Columns("B:B").ColumnWidth = 10.29
    'Columns("G:G").ColumnWidth = 11.86
    'Columns("H:H").ColumnWidth = 12
    'Columns("I:I").ColumnWidth = 11.71
     'Columns("J:J").ColumnWidth = 11.29
    'Columns("S:S").ColumnWidth = 12
    'Columns("T:T").ColumnWidth = 12.86
     ' Columns("U:U").ColumnWidth = 2.29
       
       
    Next ws
    
    
    Application.ScreenUpdating = False
    End Sub

    Thank you for your time

    Nurofen

  2. #2
    VBAX Regular Gert Jan's Avatar
    Joined
    Oct 2006
    Location
    Houten
    Posts
    62
    Location
    Two minor changes;

    [vba]Sub MyMacro12()
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
    ws.Activate

    ActiveWindow.Zoom = 75

    Columns("A:A").EntireColumn.AutoFit
    Columns("B:B").ColumnWidth = 10.29
    Columns("G:G").ColumnWidth = 11.86
    Columns("H:H").ColumnWidth = 12
    Columns("I:I").ColumnWidth = 11.71
    Columns("J:J").ColumnWidth = 11.29
    Columns("S:S").ColumnWidth = 12
    Columns("T:T").ColumnWidth = 12.86
    Columns("U:U").ColumnWidth = 2.29


    Next ws

    Application.ScreenUpdating = True
    End Sub[/vba]

  3. #3
    Hi Gert Jan,

    Thanks for helping, but that bring up.

    Run-time error'1004':

    Autofit method of Range class failed


    Thank you for your time

    Nurofen

  4. #4
    VBAX Regular Gert Jan's Avatar
    Joined
    Oct 2006
    Location
    Houten
    Posts
    62
    Location
    Maybe this is better?

    [VBA]Sub MyMacro12()
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
    ws.Activate
    ActiveWindow.Zoom = 75
    Columns("A").Columns.AutoFit
    Columns("B").ColumnWidth = 10.29
    Columns("G").ColumnWidth = 11.86
    Columns("H").ColumnWidth = 12
    Columns("I").ColumnWidth = 11.71
    Columns("J").ColumnWidth = 11.29
    Columns("S").ColumnWidth = 12
    Columns("T").ColumnWidth = 12.86
    Columns("U").ColumnWidth = 2.29
    Next ws
    Application.ScreenUpdating = True
    End Sub[/VBA]

  5. #5
    Same error Gert Jan,

  6. #6
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Quote Originally Posted by Nurofen
    Same error Gert Jan,
    Works for me
    Semper in excretia sumus; solum profundum variat.

  7. #7
    VBAX Regular Gert Jan's Avatar
    Joined
    Oct 2006
    Location
    Houten
    Posts
    62
    Location
    It works for me to,
    Can you post your workbook?

  8. #8
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    This works for me also:
    [VBA]Option Explicit
    Sub MyMacro12()
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
    ws.Activate
    ActiveWindow.Zoom = 75
    Columns("A:A").Columns.AutoFit
    Columns("B:B").ColumnWidth = 10.29
    Columns("G:G").ColumnWidth = 11.86
    Columns("H:H").ColumnWidth = 12
    Columns("I:I").ColumnWidth = 11.71
    Columns("J:J").ColumnWidth = 11.29
    Columns("S:S").ColumnWidth = 12
    Columns("T:T").ColumnWidth = 12.86
    Columns("U:U").ColumnWidth = 2.29
    Next ws
    Application.ScreenUpdating = False
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    hi,

    I'm not sure what i'm doing wrong.

    On the Front Sheet Click buttons 1 2 3 in order, the zoom works but not the columns sizes

    Sorry for Values update, just cancel a few times, its happens when you run button 2

    Thank you for your help

    Nurofen

  10. #10
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Try actually referencing the worksheet when trying to refer to the columns.
    [vba]
    With ws
    .Activate
    ActiveWindow.Zoom = 75
    .Columns("A").Columns.AutoFit
    .Columns("B").ColumnWidth = 10.29
    .Columns("G").ColumnWidth = 11.86

    .Columns("H").ColumnWidth = 12
    .Columns("I").ColumnWidth = 11.71
    .Columns("J").ColumnWidth = 11.29
    .Columns("S").ColumnWidth = 12
    .Columns("T").ColumnWidth = 12.86
    .Columns("U").ColumnWidth = 2.29
    End With[/vba]

  11. #11
    VBAX Regular Gert Jan's Avatar
    Joined
    Oct 2006
    Location
    Houten
    Posts
    62
    Location
    Quote Originally Posted by Nurofen
    hi,

    I'm not sure what i'm doing wrong.

    On the Front Sheet Click buttons 1 2 3 in order, the zoom works but not the columns sizes

    Sorry for Values update, just cancel a few times, its happens when you run button 2

    Thank you for your help

    Nurofen
    I've tried your workbook and the columns are being resized, no errors???

  12. #12
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    hmm.....going to have to give Nurofen some backing here....it doesn't seem to work for me either and I don't know why yet. It zooms to 75 ok but that's it.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  13. #13
    Hi Gert Jan,

    Now I'm confused, I can't get it to work on this side of world.
    I don't know what to say.


    Nurofen

    Ok I don't feel so silly now. lol

  14. #14
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    The locals window shows it cycling through the sheets and I am getting no errors....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  15. #15
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Norie has caught it....this works for me:
    [VBA]Private Sub CommandButton3_Click()
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
    With ws
    .Activate
    ActiveWindow.Zoom = 75
    .Columns("A").Columns.AutoFit
    .Columns("B").ColumnWidth = 10.29
    .Columns("G").ColumnWidth = 11.86

    .Columns("H").ColumnWidth = 12
    .Columns("I").ColumnWidth = 11.71
    .Columns("J").ColumnWidth = 11.29
    .Columns("S").ColumnWidth = 12
    .Columns("T").ColumnWidth = 12.86
    .Columns("U").ColumnWidth = 2.29
    End With
    Next ws
    Application.ScreenUpdating = False
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  16. #16
    VBAX Regular Gert Jan's Avatar
    Joined
    Oct 2006
    Location
    Houten
    Posts
    62
    Location
    I only checked first and last sheet, they were ok.

    I think Norie is right, this works for all sheets
    [VBA]Private Sub CommandButton3_Click()
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
    ws.Activate
    ActiveWindow.Zoom = 75
    With ws
    .Columns("A").Columns.AutoFit
    .Columns("B").ColumnWidth = 10.29
    .Columns("G").ColumnWidth = 11.86
    .Columns("H").ColumnWidth = 12
    .Columns("I").ColumnWidth = 11.71
    .Columns("J").ColumnWidth = 11.29
    .Columns("S").ColumnWidth = 12
    .Columns("T").ColumnWidth = 12.86
    .Columns("U").ColumnWidth = 2.29
    End With
    Next ws
    Application.ScreenUpdating = True
    End Sub[/VBA]

  17. #17
    VBAX Regular Gert Jan's Avatar
    Joined
    Oct 2006
    Location
    Houten
    Posts
    62
    Location
    Steve, you're to fast for me....

  18. #18
    Thank you for help- it works

    How do I stop it zooming and sizing the 1st five sheets


    Thank you for your time

    Nurofen

  19. #19
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Team effort. cudos to Norie
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  20. #20
    Thank you Norie

    Nurofen

Posting Permissions

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