+ Reply to Thread
Results 1 to 9 of 9

Formula/Macro to give active cell reference in cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Question Formula/Macro to give active cell reference in cell

    Morning,

    I'm after a formula or macro to give me the cell reference of the cell that is selected (eg A1).

    I need this reference to appear in another cell.

    How is this done please?

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Formula/Macro to give active cell reference in cell

    Hello,

    To return the selected cell address to cell A1 for example, you could use

    range("A1").Value=selection.address

    To keep the cell updated, you could use the worksheet selection_change event. Right click on the worksheet tab, select view code, and enter the following

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Range("A1").Value = Selection.Address
    End Sub
    Last edited by sweep; 06-23-2014 at 03:07 AM.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Formula/Macro to give active cell reference in cell

    Formula

    Formula: copy to clipboard
    =CELL("address",A1)
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  4. #4
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Formula/Macro to give active cell reference in cell

    OK thanks

    Does that go in the sheet code? Have tried that and nothing is happening

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Formula/Macro to give active cell reference in cell

    You could put this in the ThisWorkbook code module
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
        Call Workbook_SheetSelectionChange(Sh, Selection)
    End Sub
    
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
        ThisWorkbook.Names.Add Name:="ActiveCellAddress", RefersTo:="=""" & ActiveCell.Address(, , , True) & """"
    End Sub
    and then put the formula =ActiveCellAddress in a cell.
    Last edited by mikerickson; 06-23-2014 at 03:13 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Formula/Macro to give active cell reference in cell

    mikerickson

    Good that works - how do I change the formatting of the result so it shows just the reference without the filename and sheetname?

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Formula/Macro to give active cell reference in cell

    Change the arguments of the .Address property to suit your needs.

  8. #8
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Formula/Macro to give active cell reference in cell

    Sorry but being a noob I don't know how to?

  9. #9
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Formula/Macro to give active cell reference in cell

    This is solved now - many thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Paste issue in active cell with Macro using relative reference
    By pdjh23 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-08-2013, 03:38 AM
  2. [SOLVED] If Cell n is blank give another cell reference
    By Ninja2k in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-03-2013, 01:27 PM
  3. SUMIFS does not give a value for cell reference
    By inayat in forum Excel General
    Replies: 2
    Last Post: 09-23-2011, 03:02 AM
  4. Replies: 4
    Last Post: 02-22-2011, 10:56 AM
  5. old (Excel 2.x) macro R1C1 reference to active cell
    By riwiseuse in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-19-2010, 09:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1