Formula to output Column No. after Enter is pressed?

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hey everyone,

What formula can give me the column number of where the enter key has been pressed after editing the cell's value. My workbook is set on automatic calculations. Please note that the formula will be residing in the sheet named = Hosting , whereas it should be detecting the Enter pressed in other Sheets and thus output the column No. in numerals. perhaps a VBA to do the job?

Demonstration of the requirement:

Workbook = Project Glass
Worksheet = ABCName
Cell ref = E6
E6 = 23

User edits the above and Enter key is pressed:

Workbook = Project Glass
Worksheet = ABCName
Cell ref = E6
E6 = 50

Requirement /Output:

Workbook = Project Glass
Worksheet = Hosting
Cell ref = A1
A1 = 5

In the above example the cell A1 had the formula for extracting column which in this case was column no. 5 (for example E6)


Thank you and will appreciate any help.
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Put the following code in the events of your sheet "ABCName"

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    col = Target.Column
    Sheets("Hosting").Range("A1").Value = col
End Sub

I hope this help you
 
Upvote 0
Put the following code in the events of your sheet "ABCName"

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    col = Target.Column
    Sheets("Hosting").Range("A1").Value = col
End Sub

I hope this help you

Perfect. Would it be possible if the code be altered so that it could work for all other worksheets in the workbook and not just ABCName?

Thank you.
 
Last edited:
Upvote 0
Remove that event and put the following event in the ThisWorkook events

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Sh.Name = "Hosting" Then Exit Sub
    col = Target.Column
    Application.EnableEvents = False
    Sheets("Hosting").Range("A1").Value = col
    Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top