View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
CaptainQuattro[_3_] CaptainQuattro[_3_] is offline
external usenet poster
 
Posts: 1
Default how to copy and paste in a protected worksheet


The following macro might help:

Option Explicit
Sub CopyUnlocked()

Dim DestRow As Integer
Dim sDestRow As String

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

Range("$A$" & ActiveCell.Row).Select
Set rng = ActiveCell
Set c = ActiveCell
Set DestRange = c.Offset(DestRow - c.Row, 0)
Set d = c


Do While c.Column < 257

Do Until (c.Locked)
x = x + 1
[A1] = x
[A2] = c.Column
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
'Selection.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