VBA Intersect Error

AllisterB

Board Regular
Joined
Feb 22, 2019
Messages
120
Office Version
  1. 365
Platform
  1. Windows
I have the following code on a sheet. When I go to paset something in cell A2 it doesn't let me.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'prevents pasting onto row 1
If Not Intersect(Target, Range("1:8")) Is Nothing Then Application.CutCopyMode = False

End Sub

When I comment the code it I can paste to A2.

Row 1 is alos hidden by Grouping. When I Ungroup row 1 I am also able to paste into A2

What is wrong with my code.

Thank you

Allister
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Range("1:8") includes ALL cells in the first 8 rows of the worksheet. Your code will prevent pasting to any cell in the first 8 rows.
 
Upvote 0
Range("1:8") includes ALL cells in the first 8 rows of the worksheet. Your code will prevent pasting to any cell in the first 8 rows.
In my testing, setting CutCopyMode to False, stops the marching ants, but it doesn't empty the clipboard. Paste will still work.
Perhaps its just a Mac thing, but that approach didn't prevent pasting in my test.
 
Upvote 0
In my testing, setting CutCopyMode to False, stops the marching ants, but it doesn't empty the clipboard. Paste will still work.
Perhaps its just a Mac thing, but that approach didn't prevent pasting in my test.
In Windows it doesn't clear the clipboard either, but it prevents a paste from the right-click context menu or by using ctrl + v, or by using the Paste icon on the Home tab. If the clipboard is displayed, a paste can still be done from there.
 
Upvote 0

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

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