+ Reply to Thread
Results 1 to 2 of 2

Use a range name in VB with IF Then Else statement

  1. #1
    Registered User
    Join Date
    10-29-2005
    Posts
    16

    Use a range name in VB with IF Then Else statement

    Thanks for looking at this one.....

    when writing a macro in visual basic, how would you write code to do something like this:

    IF "Named Range 1" is not equal to "Named Range 2" THEN (do a simple cut/copy/paste which I've allready figured out) ELSE END IF

    I can do this with range as cell address ("A2") but don,t know how to reference the Named Range.

    Thanks....

    Spydor

  2. #2
    Dave Peterson
    Guest

    Re: Use a range name in VB with IF Then Else statement

    I like something like:

    if worksheets("sheet1").range("NamedRange1").value _
    = worksheets("sheet2").range("NamedRange2").value then
    'do nothing
    else
    worksheets("sheet1").range("namedrange1").value _
    = worksheets("sheet2").range("namedrange2").value
    end if

    This actually just assigns the value from namedrange2 to namedrange1.

    ===
    But I think I'd just set the values equal and get rid of the check, well, if the
    situation fit.

    spydor wrote:
    >
    > Thanks for looking at this one.....
    >
    > when writing a macro in visual basic, how would you write code to do
    > something like this:
    >
    > IF "Named Range 1" is not equal to "Named Range 2" THEN (do a simple
    > cut/copy/paste which I've allready figured out) ELSE END IF
    >
    > I can do this with range as cell address ("A2") but don,t know how to
    > reference the Named Range.
    >
    > Thanks....
    >
    > Spydor
    >
    > --
    > spydor
    > ------------------------------------------------------------------------
    > spydor's Profile: http://www.excelforum.com/member.php...o&userid=28438
    > View this thread: http://www.excelforum.com/showthread...hreadid=498554


    --

    Dave Peterson

+ 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