Solved

Detect Column index pressed in Excel

Posted on 2012-03-22
8
277 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

708 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

16 Experts available now in Live!

Get 1:1 Help Now