+ Reply to Thread
Results 1 to 3 of 3

Avoiding "If" statements in macro

  1. #1
    Registered User
    Join Date
    07-30-2008
    Location
    London
    Posts
    4

    Avoiding "If" statements in macro

    How do I write a macro that means that:

    if cell A2 displays 1, cell G2 displays whatever cell R1 displays
    else if cell A2 displays 2, cell G2 displays whatever cell R2 displays
    else if cell A2 displays 3, cell G2 displays whatever cell R3 displays
    else if cell A2 displays 4, cell G2 displays whatever cell R4 displays
    ...
    ...
    ...
    else if cell A2 displays 7051, cell G2 displays whatever cell R7051 displays.


    Without using the 7051 "If" statements.

    I was thinking something like a counting loop, but I don't know how to do that in vb. Nor do I know how to refer to cells in Excel using vb, so if somebody could show me how that would work I would greatly appreciate it.

    Many Thanks.

  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
    Welcome to the forum.

    How about just a formula? =INDEX(R:R, A2)

    If you really wanted code,

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-30-2008
    Location
    London
    Posts
    4
    I am using a macro because once I have that number I am then going to be changing the values in R1 R2 etc. and do not want the cell's number to subsequently change.

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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