+ Reply to Thread
Results 1 to 8 of 8

Putting co ordinates into excel cells using a macro

  1. #1
    Registered User
    Join Date
    04-19-2012
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    26

    Putting co ordinates into excel cells using a macro

    I'm new to vba, so bare with me.

    I'm not sure if this possible to do or not but what I would like to do is write a macro which will put in (relative reference) co ordinates into a selected range of cells.

    For example: If I select the 3x3 range A1:C3 then I want to be able to run a macro which will put the x,y coordinate (0,0) in the middle cell of the range (cell B2) and give coordinates based around this: i.e. A1 = (-1, 1), B1 = (0, 1), C1 = (1, 1), A2 = (-1, 0), B2 = (0, 0), C2 = (1, 0), A3 = (-1, 1), B3 = (0, -1), C3 = (1, -1).

    Cheers

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Putting co ordinates into excel cells using a macro

    How about just a formula? In A1 and copy across and down,

    ="(" & COLUMN() - COLUMN($B$2) & "," & ROW($B$2) - ROW() & ")"
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    04-19-2012
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Putting co ordinates into excel cells using a macro

    Love the formula. However is there way it could be modified so that the centre cell of the range is the coordinate (0,0)?

  4. #4
    Registered User
    Join Date
    04-19-2012
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Putting co ordinates into excel cells using a macro

    For instance the formula you provided has $B$2 locked in so for the example I provided above it works perferctly.

    But what about for different range?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Putting co ordinates into excel cells using a macro

    Change B2 to the center cell.

  6. #6
    Registered User
    Join Date
    04-19-2012
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Putting co ordinates into excel cells using a macro

    Yip that's what I've ended up doing.

    Cheers for your help!

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Putting co ordinates into excel cells using a macro

    Please Login or Register  to view this content.
    Last edited by shg; 04-19-2012 at 08:29 PM.

  8. #8
    Registered User
    Join Date
    04-19-2012
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Putting co ordinates into excel cells using a macro

    I was helping someone out on another forum as I once had a problem similar to theirs.

    At the moment I'm just starting out learning by looking at what the macro recorder does then modifying it...

    Sorry for not cross posting: http://www.mrexcel.com/forum/showthr...95#post3123195

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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