Select or deselect offset entire column double clicking on cell

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,</SPAN></SPAN>

I want a code that can select or deselect offset entire column double clicking on cell.</SPAN></SPAN>
For example if I double click on any cell in the column "L", I want entire column "C" could be selected. If I redo double click then entire column deselected</SPAN></SPAN>
For example if I double click on any cell in the column "N", I want entire column "D" could be selected. If I redo double click then entire column deselected</SPAN></SPAN>

Data looks as shown below</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRSTUV
1
2
3
4
5n1n2n3n4n5n6R1R2R3R4R5R6
60111210111-11
7003200000000
8014321-3113-31
9225042-4222-42
10306053-3131-33
11020070-4020-42
12031281-513-1-33
13100490-402-2-22
14211600-313-3-31
15300711-202-2-22
16010923-311-3-11
171201044-220-2-22
182311150-131-1-11
19042001-242-2-22
20153122-153-1-33
21264343064-2-44
22470450-173-1-33
235815620840-22
24092773-195-1-13
25110380401060-24
260114916-11171-13
27113000001060-22
2821412121117-1-11
2931524332128-2-22
3041630443139-3-13
31517405541410-404
3260517651311-3-15
3382620741212-2-26
3490741851113-3-17
35111853041214-2-26
36120074151113-3-17
Sheet1


Thanks In Advance </SPAN></SPAN>
Using version 2000</SPAN></SPAN>

Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hello,

From your sample ... it looks like your Offset is not constant ...

Due to all empty columns inserted from L to V ... the offset goes 9 to 14 ...

So you will need
Code:
=INT((Column()-7)/2)+MOD((Column()-7),2)

Hope this will help
 
Upvote 0
Hello,

From your sample ... it looks like your Offset is not constant ...

Due to all empty columns inserted from L to V ... the offset goes 9 to 14 ...

So you will need
Code:
=INT((Column()-7)/2)+MOD((Column()-7),2)

Hope this will help
Hello James006, thank you for looking my request, how can I use this code line I create a sub in a module and insert this line it turns red. Please can you advice or make a sub so I can use it directly</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Upvote 0
Re,

As an initial step ... you could test following :

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column < 12 And Target.Column > 22 Then Exit Sub
Dim j As Long
j = Target.Column
Cells(Target.Row, Int((j - 7) / 2) + (j - 7) Mod 2).Select
Cancel = True
End Sub

Hope this will help
 
Upvote 0
Re,

As an initial step ... you could test following :

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column < 12 And Target.Column > 22 Then Exit Sub
Dim j As Long
j = Target.Column
Cells(Target.Row, Int((j - 7) / 2) + (j - 7) Mod 2).Select
Cancel = True
End Sub

Hope this will help
James006, I would not have been able to make it worked. Thank you for building a macro. :) It works but it select only the one offset cell can you make it work so it select entire column if possible</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Upvote 0
Hello again,

Below is the requested modification :

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column < 12 And Target.Column > 22 Then Exit Sub
Dim j As Long
Dim k As Long
j = Target.Column
k = Int((j - 7) / 2) + (j - 7) Mod 2
Range(Cells(Target.Row, k), Cells(Cells(Rows.Count, k).End(xlUp).Row, k)).Select
Cancel = True
End Sub

Hope this will help
 
Upvote 0
Alternately
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column < 12 [COLOR=#ff0000]Or [/COLOR]Target.Column > 22 Then Exit Sub
Dim j As Long
Dim k As Long
j = Target.Column
k = Int((j - 7) / 2) + (j - 7) Mod 2
[COLOR=#ff0000]Columns(k).Select[/COLOR]
Cancel = True
End Sub
 
Upvote 0
Hello again,

Below is the requested modification :

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column < 12 And Target.Column > 22 Then Exit Sub
Dim j As Long
Dim k As Long
j = Target.Column
k = Int((j - 7) / 2) + (j - 7) Mod 2
Range(Cells(Target.Row, k), Cells(Cells(Rows.Count, k).End(xlUp).Row, k)).Select
Cancel = True
End Sub

Hope this will help
James006, whit this modifications I see the code select Offset to last cell not the entire column. Any ways it another idea not bad </SPAN></SPAN>

Thank you for your kind help
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Upvote 0
Alternately
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column < 12 [COLOR=#ff0000]Or [/COLOR]Target.Column > 22 Then Exit Sub
Dim j As Long
Dim k As Long
j = Target.Column
k = Int((j - 7) / 2) + (j - 7) Mod 2
[COLOR=#ff0000]Columns(k).Select[/COLOR]
Cancel = True
End Sub
Thank you Fluff, this is what I wanted it is selecting entire column Perfect! </SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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