Column Number via VBA

omairhe

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

I am trying to get the column number in Private Sub Workbook_SheetChange event code. So that if I change a cell's value the code shall output me the column number of where the change has occurred.


For instance I change a value of cell G5

In worksheet name = HSheet and cell B2 output value 7

Is possible ?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
[TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64"]In Cell B2 enter =COLUMN(Sheet1!G7)[/TD]
[/TR]
</tbody>[/TABLE]


but in VBA that would be:

Range("B2"). Value = Range("G7").column
 
Last edited:
Upvote 0
Code:
Application.EnableEvents = False
Worksheets("HSheet").[B2] = Target.Column
Application.EnableEvents = True
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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