+ Reply to Thread
Results 1 to 13 of 13

code to delete rows that cells are not highlighted

  1. #1
    Registered User
    Join Date
    03-18-2022
    Location
    london
    MS-Off Ver
    2020
    Posts
    9

    code to delete rows that cells are not highlighted

    need a macro that will delete rows in which cells are not highlighted, and then copy the results to another sheet. since data changes it can go to the last row of available data.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,021

    Re: code to delete rows that cells are not highlighted

    Just apply a filter and show or hide just the rows with the value of interest (or highlighting) and delete them or the rest. For example, filter your column F and un-check Living room - and delete everything else.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    03-18-2022
    Location
    london
    MS-Off Ver
    2020
    Posts
    9

    Re: code to delete rows that cells are not highlighted

    thanks for the reply, i understand i can filter them out but i want it to become part of a bigger macro
    that I'm trying to build which will make it completely automated. Either delete the rows or just import
    the highlighted rows with highlighted results to a different sheet

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,021

    Re: code to delete rows that cells are not highlighted

    I don't know if you want the highlighted cells moved or deleted....

  5. #5
    Registered User
    Join Date
    03-18-2022
    Location
    london
    MS-Off Ver
    2020
    Posts
    9

    Re: code to delete rows that cells are not highlighted

    I want the Rows with the highlighted cells moved to another sheet

  6. #6
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: code to delete rows that cells are not highlighted

    Quote Originally Posted by newtoexce123 View Post
    thanks for the reply, i understand i can filter them out but i want it to become part of a bigger macro
    that I'm trying to build which will make it completely automated. Either delete the rows or just import
    the highlighted rows with highlighted results to a different sheet
    Do we agree that the rows to filter are those with 'Living Room' in 'Location'?

  7. #7
    Registered User
    Join Date
    03-18-2022
    Location
    london
    MS-Off Ver
    2020
    Posts
    9

    Re: code to delete rows that cells are not highlighted

    Quote Originally Posted by beyond Excel View Post
    Do we agree that the rows to filter are those with 'Living Room' in 'Location'?
    Yes, the entire row with the highlighted text in location will be moved

  8. #8
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: code to delete rows that cells are not highlighted

    Hello.
    I assume your workbook has two sheets: Sheet1 and Sheet2:

    PHP Code: 
    Sub Filter_Ok()
    Dim Txt$, aiAdr$
    Txt "Living Room"
    With Range("Sheet1!A1").CurrentRegion
      iAdr 
    = .Columns("f").Address(external:=True)
      
    Evaluate("Transpose(((" iAdr "=""Location"") + (" iAdr "=""" Txt """)) * Row(F1:F12))")
      
    Filter(a0False): If UBound(a) = -1 Then MsgBox "No records."End
      a 
    Application.Index(.CellsApplication.Transpose(a), [{1,2,3,4,5,6}])
    End With
    Range
    ("Sheet2!A1").CurrentRegion.Delete xlShiftUp
    Range
    ("Sheet2!A1").Resize(UBound(a), UBound(a2)) = a
    End Sub 
    Last edited by beyond Excel; 10-19-2022 at 05:55 PM.

  9. #9
    Registered User
    Join Date
    03-18-2022
    Location
    london
    MS-Off Ver
    2020
    Posts
    9

    Re: code to delete rows that cells are not highlighted

    Thank you ! that worked perfectly for the provided example! How would i go about changing the code to where
    it would move the rows in the highlighted cells in the attached excel file
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: code to delete rows that cells are not highlighted

    Look: it seems to me that we are not going to the bottom of the problem, that is:

    What is the criteria you are using to highlight some cells yes and other cells no?

    > Instead of highlighting cells (an otherwise ineffective criterion): Could you include an auxiliary column marking in some way what you want to filter and copy?...

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,505

    Re: code to delete rows that cells are not highlighted

    code where it would move the rows in the highlighted cells
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 10-20-2022 at 02:23 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  12. #12
    Registered User
    Join Date
    03-18-2022
    Location
    london
    MS-Off Ver
    2020
    Posts
    9

    Re: code to delete rows that cells are not highlighted

    Quote Originally Posted by sintek View Post
    Please Login or Register  to view this content.
    Thank you!! this is exactly what i was looking for and i was able to manipulate it to what i needed do !

  13. #13
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,505

    Re: code to delete rows that cells are not highlighted

    Glad to have contributed...Tx for rep +

+ 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. delete rows highlighted with cells in A coulmn
    By kumarsandeep99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2019, 08:56 AM
  2. Find values & highlighted and delete rows
    By adeel1 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-06-2018, 10:21 AM
  3. [SOLVED] Delete Rows based on Highlighted color
    By Grahamfeeley in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-28-2017, 11:48 PM
  4. VBA to delete rows that are not highlighted
    By Pablo14 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-08-2015, 07:41 AM
  5. Delete rows if cell is not highlighted
    By perdooky in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-10-2014, 10:38 AM
  6. [SOLVED] Delete non highlighted rows with macro
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-22-2013, 08:23 AM
  7. Replies: 7
    Last Post: 05-22-2006, 04:15 AM

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