Consulting

Results 1 to 3 of 3

Thread: Select and name a Range

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Select and name a Range

    I am trying to select and name a range so that I can compare it to another range.

     
    For Each m In payrange
            If m.Value <> "" Then
            NewStuff = m.Offset(0, 1).Resize(1, 5)
            NewStuff.Select
    I thought that I was setting m.Offset(0, 1).Resize(1, 5)
    as a Range, but when I go to select it to test it, I'm getting an error.

    How do I set m.Offset(0, 1).Resize(1, 5) to a range called NewStuff, and what is the best format for comparing NewStuff to another named range?

    If OldStuff <> NewStuff Then MsgBox "NOPE!" is not working.
    Thanks

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Declaring your variable will help. Set has to be used to assign object variables.

    [VBA]Dim payrange As Range, m As Range
    Dim OldStuff As Range
    Dim NewStuff As Range

    For Each m In payrange
    If m.Value <> "" Then
    Set NewStuff = m.Offset(0, 1).Resize(1, 5)
    NewStuff.Select
    End If
    Next M[/VBA]

    This will return whether two ranges have the same values.
    [VBA]MsgBox Evaluate("SUMPRODUCT(--(" & OldStuff.Address(, , , True) & "=" & NewStuff.Address(, , , True) & "))") = OldStuff.Cells.Count[/VBA]
    Last edited by mikerickson; 01-15-2010 at 03:02 AM.

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    mikerickson :

    Thanks! I was trying to compare the values in the ranges to see if they were the same.

Posting Permissions

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