Help with VBA

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
541
Hello Folks

Ive had help to get as far as I have from people on this forum, thank you. but I'm after a little more help please.
the code does what I need it to I just need a little tweak.

it allows me to copy but when I select the next cell but it won't let me paste because it locks the cell
how do I allow it to allow a paste. ( if = pate???)
could you please help me modify the code

thank you Jason



Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect "gary"
   If Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
''Cells.Interior.ColorIndex = 0
Range("A12:MN42").Interior.ColorIndex = 0
   If Not Intersect(Target, Range("A12:MN42")) Is Nothing Then
       Target.EntireRow.Interior.ColorIndex = 6
   End If
   Application.ScreenUpdating = True
   ActiveSheet.Protect "gary"
End Sub
 
Last edited:

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
2,936
.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)


ActiveSheet.Unprotect "gary"				'<<--- this line unprotects the sheet.


   If Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
''Cells.Interior.ColorIndex = 0
Range("A12:MN42").Interior.ColorIndex = 0
   If Not Intersect(Target, Range("A12:MN42")) Is Nothing Then
       Target.EntireRow.Interior.ColorIndex = 6
   End If
   Application.ScreenUpdating = True


   ActiveSheet.Protect "gary"				'<<--- this line protects the sheet again.


End Sub





Not certain when you are "pasting" in the sheet (by using a macro), but it would need to be done somewhere between
the two comments noted above (Unprotect / Protect).


If you mean you want to manually paste in the worksheet ... you would need to remove the
two lines noted above in the macro. This will leve your sheet in unprotect mode at all times.
****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">



Not certain when you are "pasting" in the sheet (by using a macro), but it would need to be done somewhere between
the two comments noted above (Unprotect / Protect).


If you mean you want to manually paste in the worksheet ... you would need to remove the
two lines noted above in the macro. This will leve your sheet in unprotect mode at all times.
</body>
 

Forum statistics

Threads
1,084,796
Messages
5,379,933
Members
401,633
Latest member
DinnerB0ne

Some videos you may like

This Week's Hot Topics

Top