Worksheet code on double click select precise range

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Hello,

I need a worksheet code which can select precise range double clicking on cell and deselect range if one click on any cell out of that cell.

I have attached an image in which data range is D6:H39 in the range K6:K39 I have some random numbers (these numbers says how many back rows to be selected from the current row in the columns D:H) and just to have an idea in the range L6:L39 I have shown ranges to be selected while double clicking in any cell under K6:K39......

For example...in the image if double click is done on the cell K14 (which is 14 number) so it highlight in yellow or select the range D21:H34 (14 rows back from the current row in the columns D:H)

Please see the attached image...Note: Range L6:L39 is filled just for explain the idea.

*ABCDEFGHIJKLM
1
2
3Range Exapmple
4Col CCol DCol ECol FCol GNumWhen Double Click
5Col CCol DCol ECol FCol GNumHighlight Range
6111001D6:H6
7000002D6:H7
8000003D6:H8
9020122D8:H10
10000035D6:H10
11252004D8:H11
12030003D10:H12
13103022D12:H13
14012627D8:H14
15755008D8:H15
16020506D10:H16
170111345D13:H17
183125011D8:H18
19571131010D10:H19
202149146D15:H20
21406151113D9:H21
2201501119D14:H22
23014071312D12:H23
2417991216D9:H24
256603412D14:H25
26122132114D13:H26
273101413611D17:H27
28202010219D20:H28
296612138D22:H29
3081310220D11:H30
3141136419D13:H31
3203108217D16:H32
3312331212D22:H33
34151308314D21:H34
35128204615D21:H35
36502518818D19:H36
372291717521D17:H37
38131054023D16:H38
394712319D31:H39
40
41

Thank you all.

I am using Excel 2000

Regards,
Moti
 

Attachments

  • On double click select precise range.png
    On double click select precise range.png
    47.9 KB · Views: 10

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
There is a certain amount of ambiguity about your columns ..
1630493238731.png

.. but see if this is headed in the right direction.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Intersect(Target, Columns("K")) Is Nothing And IsNumeric(Target.Value) And Target.Value > 0 Then
    Cancel = True
    Target.Offset(-Target.Value + 1, -7).Resize(Target.Value, 5).Select
  End If
End Sub
 
Upvote 0
Solution
There is a certain amount of ambiguity about your columns ..
View attachment 46056
.. but see if this is headed in the right direction.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Intersect(Target, Columns("K")) Is Nothing And IsNumeric(Target.Value) And Target.Value > 0 Then
    Cancel = True
    Target.Offset(-Target.Value + 1, -7).Resize(Target.Value, 5).Select
  End If
End Sub
Peter_SSs, sorry for the inconvenience, after inserting a 1 column to left side for adjusting the correct range I forgot to correct the columns in the header.

Applied and tested the code it worked 100% perfect. (y)

Thank you very much for taking a time and solving my request.

Good Luck and have a good time always.

Kind Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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