Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Boethius1
 
Posts: n/a
Default autofit cells in column width


i have a spreadsheet that i am sharing with someone, i want to leave two
blank columns for them to use, but i want to protect the rest of the
spreadsheet.

I do not know how wide they need the columns to be as this can change,
but if i protect the sheet they cannot widen the columns themselves.

Is there a way to set the columns to autofit?
----------------------------------------------------------:)


--
Boethius1


------------------------------------------------------------------------
Boethius1's Profile: http://www.excelforum.com/member.php...o&userid=30497
View this thread: http://www.excelforum.com/showthread...hreadid=510713

  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default autofit cells in column width

You could use a worksheet event.

The code unprotects the worksheet, autofits the columns and reprotects the
worksheet.

Rightclick on the worksheet tab that should have this behavior. Select view
code and paste this into the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Unprotect Password:="password"
Me.Range("d1,F1").EntireColumn.AutoFit
Me.Protect Password:="password"
End Sub

(I used column D and F--you could do more columns (or all of them).)

Change the password to what you need.

Boethius1 wrote:

i have a spreadsheet that i am sharing with someone, i want to leave two
blank columns for them to use, but i want to protect the rest of the
spreadsheet.

I do not know how wide they need the columns to be as this can change,
but if i protect the sheet they cannot widen the columns themselves.

Is there a way to set the columns to autofit?
----------------------------------------------------------:)

--
Boethius1

------------------------------------------------------------------------
Boethius1's Profile: http://www.excelforum.com/member.php...o&userid=30497
View this thread: http://www.excelforum.com/showthread...hreadid=510713


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
Boethius1
 
Posts: n/a
Default autofit cells in column width


Thanks very much, that works great!!!!!!
----------------------------:)


--
Boethius1


------------------------------------------------------------------------
Boethius1's Profile: http://www.excelforum.com/member.php...o&userid=30497
View this thread: http://www.excelforum.com/showthread...hreadid=510713

  #4   Report Post  
Posted to microsoft.public.excel.misc
David
 
Posts: n/a
Default autofit cells in column width

That works great for the cell where data is actually entered, but it does not
work for cells with formulas. Is there anything extra I can add to also auto
adjust cells with formulas?

"Dave Peterson" wrote:

You could use a worksheet event.

The code unprotects the worksheet, autofits the columns and reprotects the
worksheet.

Rightclick on the worksheet tab that should have this behavior. Select view
code and paste this into the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Unprotect Password:="password"
Me.Range("d1,F1").EntireColumn.AutoFit
Me.Protect Password:="password"
End Sub

(I used column D and F--you could do more columns (or all of them).)

Change the password to what you need.

Boethius1 wrote:

i have a spreadsheet that i am sharing with someone, i want to leave two
blank columns for them to use, but i want to protect the rest of the
spreadsheet.

I do not know how wide they need the columns to be as this can change,
but if i protect the sheet they cannot widen the columns themselves.

Is there a way to set the columns to autofit?
----------------------------------------------------------:)

--
Boethius1

------------------------------------------------------------------------
Boethius1's Profile: http://www.excelforum.com/member.php...o&userid=30497
View this thread: http://www.excelforum.com/showthread...hreadid=510713


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default autofit cells in column width

You could use the worksheet_calculate event.

Option Explicit
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Me.UsedRange.Columns.AutoFit
Application.EnableEvents = True
End Sub



David wrote:

That works great for the cell where data is actually entered, but it does not
work for cells with formulas. Is there anything extra I can add to also auto
adjust cells with formulas?

"Dave Peterson" wrote:

You could use a worksheet event.

The code unprotects the worksheet, autofits the columns and reprotects the
worksheet.

Rightclick on the worksheet tab that should have this behavior. Select view
code and paste this into the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Unprotect Password:="password"
Me.Range("d1,F1").EntireColumn.AutoFit
Me.Protect Password:="password"
End Sub

(I used column D and F--you could do more columns (or all of them).)

Change the password to what you need.

Boethius1 wrote:

i have a spreadsheet that i am sharing with someone, i want to leave two
blank columns for them to use, but i want to protect the rest of the
spreadsheet.

I do not know how wide they need the columns to be as this can change,
but if i protect the sheet they cannot widen the columns themselves.

Is there a way to set the columns to autofit?
----------------------------------------------------------:)

--
Boethius1

------------------------------------------------------------------------
Boethius1's Profile: http://www.excelforum.com/member.php...o&userid=30497
View this thread: http://www.excelforum.com/showthread...hreadid=510713


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
David
 
Posts: n/a
Default autofit cells in column width

Now you're talking!!
I left the password lines from your previous code in and just replaced the
middle line (for the specific columns) with the three lines for the whole
worksheet (and turning off/on display).

Thanks much! Exactly what I was looking for!!

"Dave Peterson" wrote:

You could use the worksheet_calculate event.

Option Explicit
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Me.UsedRange.Columns.AutoFit
Application.EnableEvents = True
End Sub



David wrote:

That works great for the cell where data is actually entered, but it does not
work for cells with formulas. Is there anything extra I can add to also auto
adjust cells with formulas?

"Dave Peterson" wrote:

You could use a worksheet event.

The code unprotects the worksheet, autofits the columns and reprotects the
worksheet.

Rightclick on the worksheet tab that should have this behavior. Select view
code and paste this into the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Unprotect Password:="password"
Me.Range("d1,F1").EntireColumn.AutoFit
Me.Protect Password:="password"
End Sub

(I used column D and F--you could do more columns (or all of them).)

Change the password to what you need.

Boethius1 wrote:

i have a spreadsheet that i am sharing with someone, i want to leave two
blank columns for them to use, but i want to protect the rest of the
spreadsheet.

I do not know how wide they need the columns to be as this can change,
but if i protect the sheet they cannot widen the columns themselves.

Is there a way to set the columns to autofit?
----------------------------------------------------------:)

--
Boethius1

------------------------------------------------------------------------
Boethius1's Profile: http://www.excelforum.com/member.php...o&userid=30497
View this thread: http://www.excelforum.com/showthread...hreadid=510713

--

Dave Peterson


--

Dave Peterson

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
Return SEARCHED Column Number of Numeric Label and Value Sam via OfficeKB.com Excel Worksheet Functions 23 January 30th 06 06:16 PM
Positioning Numeric Values Resulting from 6 Column Array Formula Sam via OfficeKB.com Excel Worksheet Functions 2 January 5th 06 02:03 AM
hOW DO i CHANGE COLUMN WIDTH FOR ONLY A SELECT RANGE OF CELLS? RCONLON_291 Excel Discussion (Misc queries) 2 September 16th 05 11:24 AM
Comparing Cells and Displaying Data Keith Brown Excel Worksheet Functions 1 February 9th 05 05:42 PM
Change the width of a single column in a column chart Dave Charts and Charting in Excel 2 December 13th 04 07:25 PM


All times are GMT +1. The time now is 02:47 AM.

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

About Us

"It's about Microsoft Excel"