autofit column, password sheets

T

Tim

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.
 
P

Per Jessen

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
 
P

Per Jessen

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
 
T

Tim

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top