+ Reply to Thread
Results 1 to 11 of 11

vba Loop with lots of criteria

  1. #1
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    vba Loop with lots of criteria

    Hello people,

    I have got following Worksheet.
    (Master File)
    KOmhIlF.png


    I also have got a folder with Separate excel files
    that could looks like the below:

    1)
    (Slave File)
    Udzj35g.png


    2)
    (Slave File)
    DzbaqnB.png

    With my Code generates that following result:
    6PvFr4V.png

    The code does following:

    Loop through all Cells for every row in the Master file.
    for each cell open a Slave file Loop through all used cells in column in "H", If the cells are equal take the Cell same row Column "i"; paste it in the Master file to the same row as the first number but column "i"

    Now I need to also create a Critera that checks for each Slave file there is IO numbers (Column "H") that doesn't exists in the Master file if there is number that doesn't exists then, Copy the IO number + the cell same row but Column "I" To the last unused row in the Master File.

    So example:

    Master File
    [Column H][Column I]
    IO1
    IO2
    IO3
    IO4


    Slave File 1:
    [Column H][Column I]
    IO1 10
    IO2 20

    Slave File 2:
    [Column H][Column I]
    IO3 30
    IO4 40
    IO5 50 ' this info does not exists in the Master file add it to a new row.

    The final result should be like this:


    Master File:
    [Column H][Column I]

    IO1 10
    IO2 20
    IO3 30
    IO4 40
    IO5 50 ' this is the new row



    Here is my Code:

    Please Login or Register  to view this content.


    Could someone help me

    Thank you in advance

    Best Regards

    Daniel
    Last edited by elmnas; 10-22-2016 at 07:03 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: vba Loop with lots of criteria

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Re: vba Loop with lots of criteria

    Quote Originally Posted by AlphaFrog View Post
    Please Login or Register  to view this content.

    Seems to work only one problem hmm the Row that is imported if not exist, been pasted a bit lower than it supposted to be.
    see picture.
    1pEpiMm.png

    How could we fix this?

    Thank you in advance.

    best regards

    Daniel.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: vba Loop with lots of criteria

    Change this...
    x = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row

    To this...
    x = ActiveSheet.Range("H" & Rows.Count).End(xlUp).Row

  5. #5
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Re: vba Loop with lots of criteria

    Then I get this result,


    YaG1LtH.png

    notice I changed interiorcolor to =6 to see different of the unique cells that did not exists:

    Also used this code
    Please Login or Register  to view this content.

    Thank you in advance.
    Attached Images Attached Images

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: vba Loop with lots of criteria

    Try this...
    x = MasWbs.Range("H" & Rows.Count).End(xlUp).Row

  7. #7
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Re: vba Loop with lots of criteria

    Quote Originally Posted by AlphaFrog View Post
    Try this...
    x = MasWbs.Range("H" & Rows.Count).End(xlUp).Row
    Same result :
    CE2Zlki.png

    with this code ->

    Please Login or Register  to view this content.
    Thank you in advance.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: vba Loop with lots of criteria

    This is the fix

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Re: vba Loop with lots of criteria

    Quote Originally Posted by AlphaFrog View Post
    This is the fix

    Please Login or Register  to view this content.
    Works flawless Thank you!

    best regards.

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: vba Loop with lots of criteria

    You're welcome. Thanks for the feedback.

  11. #11
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Re: vba Loop with lots of criteria

    Quote Originally Posted by AlphaFrog View Post
    You're welcome. Thanks for the feedback.
    Thank you for the help a question,

    Could you explain this part

    I never used match before,

    if we don't use Match

    is there any other ways to do it?

    -->

    Please Login or Register  to view this content.
    Thank you in advance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Determine if whole number exists between a minimum and maximum value
    By ocgiraffe in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-14-2014, 11:07 AM
  2. Incrmenting a serial number + 1 if it exists -1 if it does not.
    By beenbee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2013, 07:52 AM
  3. Checking to see if a number exists in a column
    By smaier69 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2013, 12:08 PM
  4. Replies: 3
    Last Post: 01-18-2012, 07:55 AM
  5. If number exists, count cell values
    By ABBOV in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 03-25-2011, 07:31 AM
  6. modify serial number if number already exists
    By surfengine in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-05-2010, 07:49 PM
  7. Replies: 3
    Last Post: 11-13-2007, 05:13 PM
  8. Check if a number exists in a range?
    By gkaste in forum Excel General
    Replies: 2
    Last Post: 07-13-2005, 03:00 PM

Tags for this Thread

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