Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Formatting not protected when paste

If you protect a sheet's formatting, so that you can't change the formatting
with the menus, Excel still allows changing the number formatting by pasting
in from a source with different formatting. For example:

-- In Excel 2007, create a new workbook.
-- On Sheet1, select the whole sheet.
-- Right-click anywhere in the sheet and choose Format Cells | Number, and
select Text.
-- With the Format Cells dialog still open, select the Protection tab,
Uncheck "Locked", and click OK.
-- Right-click the sheet tab, and choose Protect Sheet. Make sure that
"Format cells", "Format columns", and "Format Rows" are all unchecked. Click
OK.
-- Type "001" (without quotes) in any cell, to verify that the leading zeros
are preserved due to the Text number formatting.
-- Verify that you cannot change the formatting with the menus (Format Cells
is disabled).
-- Go to Sheet2. Enter the number 5 in any cell on Sheet2. Change that
cell's font to bold and red. Copy that cell.
-- Go back to Sheet1. Paste the 5 into any cell other than the cell that
still has the "001" in it.
-- Note that the pasted 5 is bold and red, indicating that formatting was
not protected.
-- Enter "001" into the pasted cell, replacing the 5. Note that the leading
zeros are truncated.
-- Unprotect Sheet1. Right-click the pasted cell and note that the number
formatting has been changed from Text to General.

Also -- if you paste in from a rich-text source outside of Excel such as an
Outlook email, a web page, or a Word document, the number formatting of the
pasted range also changes from Text to General.


Why does this happen?

Is there a workaround that doesn't require (a) educating my tens of
thousands of users on this project to always paste-special/values, or (b)
preventing users from pasting at all and instead providing dialogs for all
input, which, no matter how well executed, would cause an uproar from users
and would not be accepted?

Greg
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Formatting not protected when paste

Greg

Such are the vagaries of Excel<g

You can retain formatting on a copy and paste with this event code in the
sheet module.

Private Sub Worksheet_Change(ByVal Target As Range)
'retain formatting when a cell is pasted over with copy.
Dim myValue
With Application
.EnableEvents = False
myValue = Target.Value
.Undo
Target = myValue
.EnableEvents = True
End With
End Sub

If you want the event for every sheet in a workbook use this in Thisworkbook
module.

Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Target As Range)
Dim myValue
With Application
.EnableEvents = False
myValue = Target.Value
.Undo
Target = myValue
.EnableEvents = True
End With
End Sub


Gord Dibben MS Excel MVP

On Wed, 15 Oct 2008 12:07:01 -0700, Greg Lovern
wrote:

If you protect a sheet's formatting, so that you can't change the formatting
with the menus, Excel still allows changing the number formatting by pasting
in from a source with different formatting. For example:

-- In Excel 2007, create a new workbook.
-- On Sheet1, select the whole sheet.
-- Right-click anywhere in the sheet and choose Format Cells | Number, and
select Text.
-- With the Format Cells dialog still open, select the Protection tab,
Uncheck "Locked", and click OK.
-- Right-click the sheet tab, and choose Protect Sheet. Make sure that
"Format cells", "Format columns", and "Format Rows" are all unchecked. Click
OK.
-- Type "001" (without quotes) in any cell, to verify that the leading zeros
are preserved due to the Text number formatting.
-- Verify that you cannot change the formatting with the menus (Format Cells
is disabled).
-- Go to Sheet2. Enter the number 5 in any cell on Sheet2. Change that
cell's font to bold and red. Copy that cell.
-- Go back to Sheet1. Paste the 5 into any cell other than the cell that
still has the "001" in it.
-- Note that the pasted 5 is bold and red, indicating that formatting was
not protected.
-- Enter "001" into the pasted cell, replacing the 5. Note that the leading
zeros are truncated.
-- Unprotect Sheet1. Right-click the pasted cell and note that the number
formatting has been changed from Text to General.

Also -- if you paste in from a rich-text source outside of Excel such as an
Outlook email, a web page, or a Word document, the number formatting of the
pasted range also changes from Text to General.


Why does this happen?

Is there a workaround that doesn't require (a) educating my tens of
thousands of users on this project to always paste-special/values, or (b)
preventing users from pasting at all and instead providing dialogs for all
input, which, no matter how well executed, would cause an uproar from users
and would not be accepted?

Greg


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
'paste special', 'paste link' formatting transfer jrebello Excel Discussion (Misc queries) 2 July 25th 07 08:46 AM
paste 'over' protected cells? George[_3_] Excel Discussion (Misc queries) 3 April 14th 07 02:14 PM
Copy/Paste a protected cell Nat1 Excel Discussion (Misc queries) 3 August 8th 05 07:23 PM
how do I cut and paste into a protected worksheet? KRISTY Excel Worksheet Functions 2 June 15th 05 11:24 AM
how do I cut and paste into a protected worksheet? KRISTYKOZMA Excel Worksheet Functions 0 June 15th 05 01:19 AM


All times are GMT +1. The time now is 04:50 PM.

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"