#1   Report Post  
Esmerelda
 
Posts: n/a
Default protecting format

I have just figured out how to protect the format of cells so that when a
date is input it always goes to the same format and font etc, and the format
cannot be changed by anyone. However, when a date cell is copied from another
excel file to my protected cell it does not revert to my desired format. How
can I ensure that whenever anything is pasted into the cell that the format
will automatically revert to my desired format? (ie without having to paste
special) - (maybe some VB code will do this???)

Thank You!
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

One way around this is to just change the number format each time a cell
changes.

You could use a worksheet event that looks for changes.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRngToCheck As Range
Dim myCell As Range

Set myRngToCheck = Me.Range("a:a")
If Intersect(myRngToCheck, Target) Is Nothing Then
Exit Sub
End If

Me.Unprotect Password:="hi"
For Each myCell In Intersect(myRngToCheck, Target).Cells
myCell.NumberFormat = "yyyy/mm/dd"
Next myCell
Me.Protect Password:="hi"

End Sub

This checks for changes in column A, then unprotects the sheet, changes the
numberformat, and reprotects the sheet.

To implement this, just rightclick on the worksheet tab that should have this
behavior. Select view code and paste this into the codewindow.

Change the range to match your worksheet, change the numberformat and change the
password (twice).

Esmerelda wrote:

I have just figured out how to protect the format of cells so that when a
date is input it always goes to the same format and font etc, and the format
cannot be changed by anyone. However, when a date cell is copied from another
excel file to my protected cell it does not revert to my desired format. How
can I ensure that whenever anything is pasted into the cell that the format
will automatically revert to my desired format? (ie without having to paste
special) - (maybe some VB code will do this???)

Thank You!


--

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
involuntary format changes dave glynn Excel Discussion (Misc queries) 2 February 23rd 05 04:29 PM
Telephone number format MarkT Excel Discussion (Misc queries) 6 January 18th 05 10:39 PM
How do i change numbers in text format to number format? Greg New Users to Excel 1 December 14th 04 05:22 PM
copy conditional format as ACTUAL format Dana Zulager Excel Discussion (Misc queries) 7 December 7th 04 11:02 PM
Copying a conditional format Meaux Excel Worksheet Functions 2 November 29th 04 10:19 AM


All times are GMT +1. The time now is 01:51 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"