+ Reply to Thread
Results 1 to 12 of 12

Adding additional IF condition

  1. #1
    Registered User
    Join Date
    11-08-2012
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    56

    Adding additional IF condition

    Hi Guys

    I have a code that searches in a column for a certain value, if it finds it, it copies this value to a range adjacent to it.

    Please Login or Register  to view this content.
    However, if the cell where the code is supposed to find a new value is blank it makes the range blank.
    But in that case, I wan't it to leave the range cells with their original value.

    I have attached a sample workbook that clarifies the problem.

    Best regards
    Danny
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: Adding additional IF condition

    Please Login or Register  to view this content.
    Click on the star if you think I helped you

  3. #3
    Registered User
    Join Date
    11-08-2012
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Adding additional IF condition

    That is the exact same code.

    So that didn't help very much..

    /Danny

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Adding additional IF condition

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-08-2012
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Adding additional IF condition

    Thank you very much for your reply.

    However the code still deletes the entries in the "Plate" column if the value in the column "Value" is empty.
    I need the code to leave the value alone except when the there is a different value.

    Br/Danny

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Adding additional IF condition

    Danny,
    There was a syntax error. If the condition was false, this line still applies
    .Value = s
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: Adding additional IF condition

    it is not the exact code. the IF - END IF was created to avoid .Value=s

  8. #8
    Registered User
    Join Date
    11-08-2012
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Adding additional IF condition

    Thanks for your help.

    But now the code only writes in one cell in the range 28-03-2014 13-30-58.png

    I need it to populate the whole "plate" range.

    Br/Danny

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Adding additional IF condition

    Danny,
    I have not set up the code-only corrected it.
    I do not know why you are using a nested loop to do this task. A simple find function will do the job.
    Is this the only condition?

    Please Login or Register  to view this content.
    Before I write a different code

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Adding additional IF condition

    I do not know where the offset should begin and end, so you need to adjust it yourself.

    This line

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by AB33; 03-28-2014 at 10:07 AM.

  11. #11
    Registered User
    Join Date
    11-08-2012
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Adding additional IF condition

    The only other condition is that if the s = .Offset(1, -1).Value is " " Then whatever there is stated in the "Plate" column stays the same.

    And also, the number of tables within each worksheet is not always the same. So I just made the loop to step through all the tables.
    Last edited by dannyjoer; 03-28-2014 at 09:11 AM.

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Adding additional IF condition

    "And also, the number of tables within each worksheet is not always the same. So I just made the loop to step through all the tables".

    is the same as looking at each cell

    Please Login or Register  to view this content.
    But the find function is faster and does not require testing it for blank cells, but the choice is yours

+ 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. Macro to format data - counting and adding additional rows on condition
    By rynofrowan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-12-2013, 11:46 PM
  2. [SOLVED] VLOOKUP??? With additional condition??
    By wpnsx in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-11-2013, 12:48 PM
  3. Add additional condition to this code
    By rlsublime in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-14-2012, 03:58 PM
  4. Replies: 4
    Last Post: 04-22-2012, 07:55 AM
  5. COUNTA-formula with additional condition
    By BCB in forum Excel General
    Replies: 5
    Last Post: 12-14-2006, 02:48 PM

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