1004' method 'range' of object '_worksheet' failed

adamcfishman

New Member
Joined
Jul 18, 2011
Messages
5
Please Please Please Help :)
This is currently working but when I try and add more cells to reference it gives me a dreaded "1004' method 'range' of object '_worksheet' failed" error. Does anyone have any suggestions or feedback?


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

'if they double click on the cell once it shows "a" in marlett,
'if they double-click on it again it shows "r" in Marlett.
'Then if they click on it a third time it is blank ""

If Target.Count > 1 Or Intersect(Target, Range("k3:k6, l3:l6, z3:ab3, z5:aa6, k11:l11, k12:m16, z11:ab14, z22:z27, ab22:ab27, k31:m32, z31:ab32, x44:x59, z44:z59, aa44, aa46, aa48, aa50, aa52, aa54, aa56, aa58, k63:m64, k68:m68, z69:aa69, k85:l87, l97:m98, l100:m100, l103:m103, l107:m107, z85:aa86, z88")) Is Nothing Then Exit Sub
Select Case Target.Value
Case Is = ""
Target.Font.Name = "Marlett"
Target.Value = "a"
Case Is = "a"
Target.Font.Name = "Marlett"
Target.Value = "r"
Case Is = "r"
Target.ClearContents
End Select
Cancel = True
End Sub

Thanks for your help.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You could make a Named range for these cells.
Then in your code, you can simply replace all these cell address with the name of the named range.
 
Upvote 0
Select the cells using the Ctrl key, and in the Name box (to the left of the formula bar) type in the name. Next:

Code:
If Target.Count > 1 Or Intersect(Target, Range("MyRange")) Is Nothing Then Exit Sub

Change MyRange for the name you just used.
 
Upvote 0
As well as Wigi's suggestion I think you can probably combine some of those ranges.

eg K3:K6, L3:L6 = K3:K6

You've also got K12:M16, K32:M32, K63:M64 ... Z11:AB14 and so on.

Then there's the columns - you only seem to be working with columns, K:M, X and Z:AB.

So you could check the column first:
Code:
If Target.Count > 1 Or Intersect(Target, Range("L:M, X:X, Z:AB")) Is Nothing Then Exit Sub
 
Upvote 0
@ wigi, works like a champ, thank you so much for your help.

@ Norie, There are a lot of merged cells I was under the impression that column selection is not possible in that scenario or is it stillpossible with merged cells? In any case that you for your feedback.
 
Upvote 0
Adam

Sorry I don't quite understand, there's no selection in the code I posted.

I've you mean that the code won't get triggered at all when a merged cell is selected then you can just remove the Target.Count part.

You might also need to change the Select case:
Code:
Select Case Target.Cells(1, 1).Value


Or, and this is perhaps better overall, get rid of the merged cells.:)
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

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