LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to copy and paste in a protected worksheet


I have written the following macro that copies from all the unprotected
cells in the active cell row and pastes to the corresponding cells in
another row.

The benefit of doing this as opposed to simply unlocking the
destination range, pasting and locking it again is that there is no
guarantee that the locked cells in the destination range are blank or
contain exact copies of the formulas in the source range.

DISCLAIMER/WARNING:

THIS IS BRAND NEW CODE, SO PLEASE USE EXTREME CAUTION, AND MAKE
MULTIPLE BACKUPS OF YOUR FILE BEFORE YOU START TO TEST.

Option Explicit
Sub CopyUnlocked()

Dim DestRow As Integer

DestRow = Application.InputBox(Prompt:="Enter Destination Row",
Title:="DestinationRow", Type:=1)
Dim c As Range
Dim DestRange As Range
Dim rng As Range


Range("$A$" & ActiveCell.Row).Select
Set c = ActiveCell

If (c.Locked) Then
Do Until Not (c.Locked)

If c.Column = 256 Then
Exit Do
End If

Set c = c.Offset(0, 1)
Loop
End If




Do While c.Column < 257

If (c.Locked) Then
Do Until Not (c.Locked)
If c.Column = 256 Then
Exit Do
End If
Set c = c.Offset(0, 1)
Loop
End If

Set rng = c
Set DestRange = c.Offset(DestRow - c.Row, 0)

Do Until (c.Locked)

Set c = c.Offset(0, 1)

If (c.Locked) Then
Exit Do ' Exit the do until loop
End If


Set rng = Union(rng, c)

If c.Column = 256 Then
Exit Do ' exit the do until loop
End If


Loop


rng.Copy
DestRange.PasteSpecial xlPasteValues
Range("$A$" & DestRange.Row).Select

If c.Column = 256 Then
Exit Do ' exit the do WHILE loop
End If

Set c = c.Offset(0, 1)
Set rng = c
Set DestRange = c.Offset(DestRow - c.Row, 0)


Loop
End Sub


--
CaptainQuattro
------------------------------------------------------------------------
CaptainQuattro's Profile: http://www.excelforum.com/member.php...o&userid=32763
View this thread: http://www.excelforum.com/showthread...hreadid=571191

 
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
Copy & paste to protected sheet nc Excel Discussion (Misc queries) 3 July 5th 09 10:38 PM
how to copy and paste in a protected worksheet CaptainQuattro[_3_] Excel Programming 0 August 14th 06 04:04 AM
allow me to copy and paste in a protected worksheet George New Users to Excel 3 August 13th 06 08:11 PM
copy and paste from and to protected sheets Tonso Excel Programming 1 June 23rd 06 06:40 PM
Can't copy & paste row inside a protected worksheet giloboy Excel Programming 6 September 21st 04 06:43 PM


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