Dynamic Cell setup (Based on click to copy)- Error 91

Sinvoid

New Member
Joined
Oct 1, 2013
Messages
2
So here is my code
Code:
Sub Worksheet_SelectionChange(ByVal Target As Range) 'single click version 
 Range("J3:J32").Interior.Color = RGB(200, 160, 35)
 Range("K3:K3").Interior.Color = RGB(200, 160, 35)
 
    If Intersect(Target, Range("J3")) Or Intersect(Target, Range("J4")) Is Nothing Then Exit Sub
    ActiveCell.Copy


     
End Sub

The If statement line gives me a 91 error. Simply right now i'm trying to allocate several squares in the sheet to be cells that when clicked will copy to your clipboard automatically. I can do 1 range easy but now i need to make it a little more advanced.
 
Sinvoid,

Welcome to the forum.

Try...

Rich (BB code):
If Intersect(Target, Range("J3")) Is Nothing Or Intersect(Target, Range("J4")) Is Nothing Then Exit Sub

Hope that helps.
 
Upvote 0
Sinvoid,

Welcome to the forum.

Try...

Rich (BB code):
If Intersect(Target, Range("J3")) Is Nothing Or Intersect(Target, Range("J4")) Is Nothing Then Exit Sub

Hope that helps.

So that removed my error however that created the situation where either of the blocks will not copy unless both are highlighted simultaneously. Which seems odd because it's OR and not AND that connects them.
 
Upvote 0
Your code currently colours J3:J32 and K3
Then unless J3 AND K3 are selected, it will exit the sub and not copy.

If you want it to copy either J3 or J4, or both then you must have

Rich (BB code):
If Intersect(Target, Range("J3")) Is Nothing And Intersect(Target, Range("J4")) Is Nothing Then Exit
 
Upvote 0

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