+ Reply to Thread
Results 1 to 10 of 10

LBound/UBound Intersect together

  1. #1
    Registered User
    Join Date
    03-12-2013
    Location
    Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    13

    Question LBound/UBound Intersect together

    Hi guys.

    How can I make this code working? It should take cell from rng2, go through first row in rng1, compare it and if it doesn't find match, paste this cell in somewhere (destination is irrelevant).

    Please Login or Register  to view this content.
    Thanks

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: LBound/UBound Intersect together

    L/Ubound function is for vba arrays. not for Ranges.....

    This is only my guess
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,952

    Re: LBound/UBound Intersect together

    I'm not sure what you are doing. Does this help in the right direction?
    Please Login or Register  to view this content.


    Some Notes

    Set FirstRow = rng2.Rows(1)
    Set FRow = rng1.Rows(1)


    These lines set the variables to the first cell of each range.

    Since they are one cell ranges and not arrays, For j = LBound(FirstRow) To UBound(FirstRow) will error out because UBound/LBound return the first and last indices of arrays
    (this looks like you are trying to step trough a range of cells with your loop)

    variable j: is a number but Intersect(j, FRow) requires range parameters, testing to see if the address of the one is contained in the other

    Selection.Copy: Since you don't select anything with your code, Selection is whichever cell on the sheet just happened to be selected if the code had run (it won't). Nor will it ever change via your code.

    Else: You don't carry out any process when the If returns a False, therefore you don't need the Else line.
    Last edited by protonLeah; 04-20-2013 at 08:23 PM. Reason: expansion re:
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    03-12-2013
    Location
    Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: LBound/UBound Intersect together

    jindon: Thanks, but doesn't help
    protonLeah: I'm trying to compare two tables (only their headings) and find the difference. => trying to merge these tables, so I must find which headings aren't use in first table (hope you understand )

    so I try overwrite your code with this:

    Please Login or Register  to view this content.
    But the result: Run-time error '13': Type Mismatch.
    I know that For Each FirstRow In FirstRow might not be the right solution, but I don't want to define sheet as BaseRange/TestRange. Both tables are on the same sheet.
    You didn't define TestRow/BaseRow, so I guess they don't have to be, am I right?
    Last edited by janulikb; 04-21-2013 at 02:22 AM.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: LBound/UBound Intersect together

    My guess was close... but couldn't read what yuou are trying to do from your original code...
    Please Login or Register  to view this content.
    But it still doesn't make sence to me.
    What do you mean by "rying to merge these tables", anyway?
    Last edited by jindon; 04-21-2013 at 03:40 AM.

  6. #6
    Registered User
    Join Date
    03-12-2013
    Location
    Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: LBound/UBound Intersect together

    I rewrite it with this:

    Please Login or Register  to view this content.
    but the same error occures in this line If r.Value <> c.Value Then

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: LBound/UBound Intersect together

    1) Only the case I can think of is that there are Error value in the cell(s).

    There shouldn't be .Paste
    2) Destination:=Range("A1").End(xlToRight).Offset(0, 2).Paste

    Really hard to understand from your code....

  8. #8
    Registered User
    Join Date
    03-12-2013
    Location
    Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: LBound/UBound Intersect together

    I don't know if this help, but here is an example:

    test.jpg

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: LBound/UBound Intersect together

    You should have posted that in the first place.
    Please Login or Register  to view this content.
    Or maybe
    Please Login or Register  to view this content.
    Last edited by jindon; 04-21-2013 at 05:06 AM.

  10. #10
    Registered User
    Join Date
    03-12-2013
    Location
    Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: LBound/UBound Intersect together

    Graaaacias. Finally it's working

+ 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