Solved

Detect Column index pressed in Excel

Posted on 2012-03-22
8
293 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 37757005
You gonna request attention ?
0
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

832 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