ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to copy and paste in a protected worksheet (https://www.excelbanter.com/excel-programming/370252-re-how-copy-paste-protected-worksheet.html)

CaptainQuattro[_3_]

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



All times are GMT +1. The time now is 03:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com