Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
bob bob is offline
external usenet poster
 
Posts: 52
Default simple question

The formula =ROW(G11) returns the value 11

I need VBA Code that will return the row value of the
active cell. For example, I want the value of Sheet1:A1
to be the current active cell value (i.e if the current
active cell is G11 the value returned for Sheet1:A1 would
be 11).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default simple question

Bob,

this is not fully tested but seems to do the job WHEN the sheet is
calculated. It won't change if you simply change the selection.

Public Function ActiveCellAddress() As Variant
Dim rngCell As Range
Application.Volatile

On Error Resume Next
Set rngCell = ActiveCell
On Error GoTo 0

If Not rngCell Is Nothing Then
ActiveCellAddress = rngCell.Address
Else
ActiveCellAddress = CVErr(xlErrNA)
End If
End Function

If you need something that changes every time the selection is changed then
put this in the code behind the worksheet.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Target Is Nothing Then
Range("a1").Value = ActiveCell.Address
'or if you want the whole selected range
'Range("a1").Value = Target.Address
'or if you want the top left cell in the selected range
'Range("a1").Value = Target(1,1).Address
End If
End Sub


Robin Hammond
www.enhanceddatasystems.com

"bob" wrote in message
...
The formula =ROW(G11) returns the value 11

I need VBA Code that will return the row value of the
active cell. For example, I want the value of Sheet1:A1
to be the current active cell value (i.e if the current
active cell is G11 the value returned for Sheet1:A1 would
be 11).



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default simple question

Hi Bob,

Try:

ActiveCell.Row

---
Regards,
Norman



"bob" wrote in message
...
The formula =ROW(G11) returns the value 11

I need VBA Code that will return the row value of the
active cell. For example, I want the value of Sheet1:A1
to be the current active cell value (i.e if the current
active cell is G11 the value returned for Sheet1:A1 would
be 11).



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default simple question

On Thu, 16 Sep 2004 17:23:05 -0700, "bob"
wrote:

The formula =ROW(G11) returns the value 11

I need VBA Code that will return the row value of the
active cell. For example, I want the value of Sheet1:A1
to be the current active cell value (i.e if the current
active cell is G11 the value returned for Sheet1:A1 would
be 11).


Right click on the sheet tab and select View Code.

Paste the following code into the window that opens:

=================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
[a1].Value = activecell.Row
End Sub
=====================

This will work on the worksheet that you selected.


--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Simple question belto New Users to Excel 2 December 4th 07 11:01 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM
(Simple) VBA Question Matt[_10_] Excel Programming 2 August 12th 03 11:12 PM


All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"