+ Reply to Thread
Results 1 to 4 of 4

How do I loop through each CELL in a named range and compare to another range for matches?

  1. #1
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    326

    How do I loop through each CELL in a named range and compare to another range for matches?

    Hi,

    I have ListBox on a UserForm that pre-loads items from a list ("TheList") and then pre-loads the already selected items on that list from another list ("TheListSelected"). It works perfectly except for one little thing. I would like to relocate the TheList to another sheet but the code uses CELL and OFFSET and I don't know how to get them to read from a range on another sheet.

    I've attached the file, but the code I ned to change is pasted below in bold:

    Please Login or Register  to view this content.
    Is this just a small tweak of code?

    Lawrence

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

    Re: How do I loop through each CELL in a named range and compare to another range for matc

    In the code shown, you are declaring a range variable "Cell" that has the same name as the VBA key word CELL. You must never do that; try something descriptive like TestCell or CurrentCell.

    The sheet with the tabname "HappySheet" has the Excel/VBA code name Sheet1. So, if you move your list to a different sheet, the code in procedure
    CommandButton1_Click() which has a line: Sheet1.Cells(5, 3).Resize(65531, 1).ClearContents will have to be changed to Sheets("othersheetname"). ...
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    326

    Re: How do I loop through each CELL in a named range and compare to another range for matc

    Thanks! And I thought CELL was a method. <rolling my eyes>

    What about in Userform_Initialize how do I change If cell.Offset(, 2).Value = cell.Value

    Such that If cell.Offset(, 2).Value refers to seperate range called "TheListSelected"?

    Lawrence

  4. #4
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    326

    Re: How do I loop through each CELL in a named range and compare to another range for matc

    Would it be something like:

    Please Login or Register  to view this content.
    Lawrence

+ 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