+ Reply to Thread
Results 1 to 8 of 8

VBA Conditional formatting to delete entire row when two variable are ture

  1. #1
    Registered User
    Join Date
    08-01-2011
    Location
    Tasmania, Australia
    MS-Off Ver
    Excel 2007
    Posts
    12

    Question VBA Conditional formatting to delete entire row when two variable are ture

    Hi all,

    In my on-going work project (that i thought was finished ><) I have code that basically does this:

    IF cell1 = cell2 THEN highlight entire row Blue.
    IF cell3 = cell4 THEN highlight entire row Red.

    This obviously cause problems when both are true as the as the you can't see both colours.

    Is it possible to have something to the effect of:

    IF cell1=cell2 AND cell3=cell4 THEN delete entire row.

    I have tried a few variations that sound intuitive, but I cant seem to get the code syntax right.

    Thanks for any help you can give me, much appreciated!

    ADTC.

  2. #2
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327

    Re: VBA Conditional formatting to delete entire row when two variable are ture

    Hi ADTC,

    You could try this code

    Please Login or Register  to view this content.
    Hope this helps

    Seamus

  3. #3
    Registered User
    Join Date
    08-01-2011
    Location
    Tasmania, Australia
    MS-Off Ver
    Excel 2007
    Posts
    12

    Question Re: VBA Conditional formatting to delete entire row when two variable are ture

    Hi SOS, thanks for the response. I'm still having a little trouble getting it to compile - errors all over the place due to my existing code.

    How would I incorporate your code in to mine:


    Please Login or Register  to view this content.
    Thanks again for all your help!
    Last edited by adtc; 08-13-2011 at 09:32 PM. Reason: rule 3 of guidelines

  4. #4
    Registered User
    Join Date
    08-01-2011
    Location
    Tasmania, Australia
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: VBA Conditional formatting to delete entire row when two variable are ture

    Quote Originally Posted by Mordred View Post
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    my apologies, thanks for the reminder.

    thanks again in advance to anyone that can help me with this coding.

  5. #5
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327

    Re: VBA Conditional formatting to delete entire row when two variable are ture

    Hi

    I've edited the code by adding a variable (x) which increments each loop to determine which row to delete.

    Please let me know how it goes
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-01-2011
    Location
    Tasmania, Australia
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: VBA Conditional formatting to delete entire row when two variable are ture

    Hi SOS,

    Thanks for working out the re-wite for me. I have just given it a go but it doen't quite work.
    The formatting works perfectly, it's just the loop for deleting the rows where [cel1= cell2 AND cell3=cell4].

    At present, it looks like it is only deleting the very first row, from the bottom, where cell1=cell2 which it should not delete as it does not satisfy the criteria for deletion: [cel1= cell2 AND cell3=cell4].
    After it deleted that first row, the loop/macro stops.

    Hope this helps .
    And thanks again for going to the trouble of helping my get this working.
    I can send you a mock workbook if you need.

    ADTC.

  7. #7
    Registered User
    Join Date
    08-01-2011
    Location
    Tasmania, Australia
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: VBA Conditional formatting to delete entire row when two variable are ture

    I've uploaded to mock workbooks.

    One with VB code already in (for reference if needed)
    http://dl.dropbox.com/u/8139608/VBmock.xls
    And a second with No VB code if you like a clean slate, but need to see how it should look.
    http://dl.dropbox.com/u/8139608/NO-VBmockmock.xls

    Hope this helps
    Thanks for all your hard work.
    I look forward to seeing what you come-up with if you have some free time

    ADTC

  8. #8
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327

    Re: VBA Conditional formatting to delete entire row when two variable are ture

    Hi adtc,

    Try this code. I've added a loop at the end of the Sub which loops backwards from the bottom most cell in Col J and checks its interior colour, then check the interior of the corresponding cell in Col E and if both conditions are met then it deletes the row.

    You should also declare each variable as a range.

    Give it a shot and post back please

    Please Login or Register  to view this content.
    Last edited by SOS; 08-15-2011 at 05:15 PM. Reason: Slight change to code example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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