Results 1 to 4 of 4

Macro: assign value of x-y postion

Threaded View

  1. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro: assign value of x-y postion

    james.carey,

    Welcome to the Excel forum.


    I assume that your coordinates are in columns A and B, and begin in row 2.

    The macro will check the coordinates, and if they are not valid, they will be highlighted RED.


    Detach/open workbook SetXY coorinates equal to 1 - james_carey - EF776351 - SDG13.xls and run macro SetXY.



    If you want to use the macro on another workbook:


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


    
    Option Explicit
    Sub SetXY()
    ' stanleydgromjr, 05/17/2011
    ' http://www.excelforum.com/excel-programming/776351-macro-assign-value-of-x-y-postion.html
    Dim c As Range
    Application.ScreenUpdating = False
    For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
      If c = "" Or c < 1 Or c > Rows.Count And c.Offset(, 1) = "" Or c.Offset(, 1) < 1 Or c.Offset(, 1) > Columns.Count Then
        c.Resize(, 2).Interior.ColorIndex = 3
      Else
        Cells(c.Value, c.Offset(, 1).Value) = 1
      End If
    Next c
    Application.ScreenUpdating = True
    End Sub

    Then run the SetXY macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

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