Solved

Detect Column index pressed in Excel

Posted on 2012-03-22
8
284 Views
Last Modified: 2012-03-23
Hello EE,

How can I know via code (macro)  which column index was Clicked (cell or header)  ?

What is the code behind for that ?

if I press Cell (3,3)  I would like to know that it was Column 3   or ("C")
0
Comment
Question by:PhilippeRenaud
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:kgerb
ID: 37754526
put the following in the worksheet code pane for the desired worksheet.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox "A cell in column " & Target.Column & " was clicked"
End Sub

Open in new window

Kyle
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 37756819
Ok, do you know maybe was is the difference in VB ?
actually its a Excel control I have and I have the same possible event except that it goes as follow:


Private Sub AxSpreadsheet2_SelectionChange(sender As Object, e As System.EventArgs) Handles AxSpreadsheet2.SelectionChange

End Sub


I dont have Target as Range inside... the parameter is  e as EvenArgs...

maybe it's out of your scope ?
0
 
LVL 12

Expert Comment

by:kgerb
ID: 37756919
Yeah, I'm not up on .Net.  Just VBA.  I'll go get help.

EDIT:
Ok, the cavalry will be here soon.

Kyle
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 37757005
You gonna request attention ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:kgerb
ID: 37757049
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 37757068
thanks, If I may... also, I was asking this quesiton because I was trying to get the column click when a user delete the entire column.

I have 2 Spreadsheet and when the user delete a column I wanted to programmatically delete the same column on the other spreadsheet...but looks like there is no event for the column deleted...

so I thought If I can know the column index before then I compare the excel sheets.. I could my self delete the column
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 37757074
I suspect that Sender.Selection.Column would be the syntax though you may have to cast Sender as AxSpreadsheet first. e might also be the range itself.
0
 
LVL 1

Author Closing Comment

by:PhilippeRenaud
ID: 37757384
Thanks, also I have a bigger problem related to Excel Control on this question :


http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_27635758.html


Any idea excel experts? Im getting crazy not finding a solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now