Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default autofit column, password sheets

Hi there,
I have a workbook that is made up of 26 sheets, that are 20 columns wide,
are password protected. I want only 24 of the sheets and only 2 of these
columns in each sheet to automatically fit the text typed in to them, and the
rest of the columns stay the same. Does anyone have any idea on what code to
use? Thanks for your time.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default autofit column, password sheets

Hi

Change NotThisSheet and NotThisSheet2 to the names of sheets to exclude from
autofit. This macro will autofit column 2 and 5 if they are changed.

As this is an event macro it has to be inserted into the codesheet for
ThisWorkbook

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name < "NotThisSheet" And Sh.Name < "NotThisSheet2" Then
If Target.Column = 2 Or Target.Column = 5 Then
Target.EntireColumn.AutoFit
End If
End If
End Sub


Regards,
Per

"Tim" skrev i meddelelsen
...
Hi there,
I have a workbook that is made up of 26 sheets, that are 20 columns wide,
are password protected. I want only 24 of the sheets and only 2 of these
columns in each sheet to automatically fit the text typed in to them, and
the
rest of the columns stay the same. Does anyone have any idea on what code
to
use? Thanks for your time.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default autofit column, password sheets

I forgot the password issue, try this version:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name < "NotThisSheet" And Sh.Name < "NotThisSheet2" Then
If Target.Column = 2 Or Target.Column = 5 Then
Sh.Unprotect Password:="JustMe"
Target.EntireColumn.AutoFit
Sh.Protect Password:="JustMe"
End If
End If
End Sub

Regards,
Per

"Per Jessen" skrev i meddelelsen
...
Hi

Change NotThisSheet and NotThisSheet2 to the names of sheets to exclude
from autofit. This macro will autofit column 2 and 5 if they are changed.

As this is an event macro it has to be inserted into the codesheet for
ThisWorkbook

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Sh.Name < "NotThisSheet" And Sh.Name < "NotThisSheet2" Then
If Target.Column = 2 Or Target.Column = 5 Then
Target.EntireColumn.AutoFit
End If
End If
End Sub


Regards,
Per

"Tim" skrev i meddelelsen
...
Hi there,
I have a workbook that is made up of 26 sheets, that are 20 columns wide,
are password protected. I want only 24 of the sheets and only 2 of these
columns in each sheet to automatically fit the text typed in to them, and
the
rest of the columns stay the same. Does anyone have any idea on what code
to
use? Thanks for your time.



  #4   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default autofit column, password sheets

Hi there,
I just realized that half the sheets are in columns G and H ... and the
other half of the sheets is in I and J. I will have to have 2 types of code
and put in 'each' sheet instead of ThisWorkbook. Do you know how I revise?
Thanks

"Per Jessen" wrote:

I forgot the password issue, try this version:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name < "NotThisSheet" And Sh.Name < "NotThisSheet2" Then
If Target.Column = 2 Or Target.Column = 5 Then
Sh.Unprotect Password:="JustMe"
Target.EntireColumn.AutoFit
Sh.Protect Password:="JustMe"
End If
End If
End Sub

Regards,
Per

"Per Jessen" skrev i meddelelsen
...
Hi

Change NotThisSheet and NotThisSheet2 to the names of sheets to exclude
from autofit. This macro will autofit column 2 and 5 if they are changed.

As this is an event macro it has to be inserted into the codesheet for
ThisWorkbook

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Sh.Name < "NotThisSheet" And Sh.Name < "NotThisSheet2" Then
If Target.Column = 2 Or Target.Column = 5 Then
Target.EntireColumn.AutoFit
End If
End If
End Sub


Regards,
Per

"Tim" skrev i meddelelsen
...
Hi there,
I have a workbook that is made up of 26 sheets, that are 20 columns wide,
are password protected. I want only 24 of the sheets and only 2 of these
columns in each sheet to automatically fit the text typed in to them, and
the
rest of the columns stay the same. Does anyone have any idea on what code
to
use? Thanks for your time.



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Column Autofit mcolson Excel Discussion (Misc queries) 2 March 6th 08 10:19 PM
Column Autofit Karen McKenzie Excel Programming 2 April 23rd 07 01:16 PM
macro takes 30+ seconds to do an autofit on only 1 out of the 3 sheets it is autofitting drdavidge Excel Programming 9 July 13th 06 08:19 PM
macro takes 30+ seconds to do an autofit on only 1 of 3 sheets it is autofitting drdavidge Excel Worksheet Functions 1 July 13th 06 05:48 PM
Excel password but cant hide the sheets before entering password cakonopka[_3_] Excel Programming 1 January 30th 04 06:28 PM


All times are GMT +1. The time now is 12:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"