How can you get the cell number of a selected cell

Lowell In the south

Board Regular
Joined
Sep 26, 2002
Messages
55
I have a macro that selects a cell I need to know the number of the cell it selects to use in another macro?
THANKS FOR LOOKING
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

stevebausch

Well-known Member
Joined
May 11, 2002
Messages
810
With ActiveCell

or

With Selection(1,1)


.Row
.Column
.Rows.Count
.Columns.Count


Which Excel are you targeting? 97 and 2002 will accept the same code, IF you are EXTREMELY CAREFUL about coding.

Merged cells are the bugaboo; I suggest the following:

If you use "Set" statements to create Range variables to refer to merged cells, the variable should reference the top left cell, only.

Don't expect to .ClearContents, instead use ".Value = vbNullString"

Any of the _Change events that have the argument "Target as Range" will return a vartype() of array in 97, in 2002, the Vartype will be the variable contained. To deal with potential type mismatches, it is best to use the Target(1,1) construct. That will keep 97 and 2002 happy.

If you do use Range variables, just keep in mind that any run-time error that halts the code will set the Range variable to Nothing. I compensate by having all the "Set n = Cells(row,col)" Range variable assignments in their own routine, and calling it in my error handling routines, just in case.

For the Real Gurus out there, please suggest improvements/corrections to anything said here. I will appreciate.

Steve

_________________
This message was edited by stevebausch on 2002-10-24 21:57
 

Lowell In the south

Board Regular
Joined
Sep 26, 2002
Messages
55
I have a macro that selects a cell using
For Each cl In Rg
If cl = "" And cl.MergeArea.Columns.Count = 1 And Not cl.EntireColumn.Hidden And Not cl.EntireRow.Hidden And cl.Column <= C - cn And cl.Row <= r - rn Then

I need to know the cell number of the cell selected.
 

Lowell In the south

Board Regular
Joined
Sep 26, 2002
Messages
55
I got it thanks!!!

TextBox1.Text = cl

Does not give the cell range but it will place the contience of the selected cell in a textbox which is what i was lookin for!

THANKS FOR LOOOKING!!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,396
Messages
5,601,414
Members
414,449
Latest member
Pashtun

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
Top