Solved

Detect Column index pressed in Excel

Posted on 2012-03-22
8
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

615 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