Detect Column index pressed in Excel

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")
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kgerbChief EngineerCommented:
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

PhilippeRenaudAuthor Commented:
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 ?
kgerbChief EngineerCommented:
Yeah, I'm not up on .Net.  Just VBA.  I'll go get help.

Ok, the cavalry will be here soon.

JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

PhilippeRenaudAuthor Commented:
You gonna request attention ?
kgerbChief EngineerCommented:
PhilippeRenaudAuthor Commented:
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
Rory ArchibaldCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PhilippeRenaudAuthor Commented:
Thanks, also I have a bigger problem related to Excel Control on this question :

Any idea excel experts? Im getting crazy not finding a solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.