Solved

Active RowFunction in Excel 2007

Posted on 2012-03-12
3
327 Views
Last Modified: 2012-03-12
I'm tyring to create a function that would always display the row of the active cell in the cell you place the funtion in. In other words, if I placed '=ShowRow()' in Cell A3, then the value in Cell A3 should always be the row of the active cell; everytime you click on a different cell, the value in Cell A3 should automatically update to indicate the row of the active cell.

I tried this code in VBA:

Function ShowRow()
ShowRow = ActiveCell.Row
End Function

Which works ok the first time you type it, but it doesn't update as you select different cells in the spreadsheet. Seems like there should be a standard Excel function to do this, but apparently not.
0
Comment
Question by:restabro
[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
3 Comments
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 250 total points
ID: 37711855
Hello,

this code will show the row of the current cell in A1

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Range("A1") = Target.Row
End Sub

This code needs to go into the Sheet module (right-click the sheet tab  > View Code > Paste the code into the code window).

cheers, teylyn
0
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 250 total points
ID: 37711864
Right-click on the sheet tab name
Select view code
Paste this code there

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("A1").Value = ActiveCell.Row
End Sub
0
 

Author Closing Comment

by:restabro
ID: 37711977
Both responses worked and I really appreciate the detailed instructions on how to apply it! Thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

690 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