Help with VBA

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
743
Office Version
  1. 365
Platform
  1. Windows
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:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
.
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>
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top