+ Reply to Thread
Results 1 to 12 of 12

Remove Data from rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,744

    Remove Data from rows

    Hello,

    Can you please create me a macro that will Delete the data that has ?YES? in column H4:H3000 and it will leave no empty rows from A4:H3000 (Sheet1)

    See attachment.

    Thank you in advance!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    928

    Re: Remove Data from rows

    This could be a macro for you, have a try on a test file.
    Option Explicit
    Sub DeleteItems()
        With Sheets("Sheet1").Range("$B3:$H$3000")         '<- use this is for a static range
        'With Sheets("Sheet1").Range("$B3:$H$" & Cells(Rows.Count, "B").End(xlUp).Row) '<- use this instead for a dynamic range
            Sheets("Sheet1").AutoFilterMode = False
            .AutoFilter Field:=7, Criteria1:="YES", Operator:=xlFilterValues
            .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
            Sheets("Sheet1").AutoFilterMode = False
        End With
    End Sub
    Last edited by rollis13; 03-24-2023 at 02:02 PM.

  3. #3
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,744

    Re: Remove Data from rows

    Hello,

    It worked! Thank you.

    Will be able also to make me a macro for Duplicate Entry in Column B4:B3000?
    Delete the duplicate and leave no empty rows as well.

    I want it a separate button, if you can. Thank you so much

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    928

    Re: Remove Data from rows

    Sorry, this is a completely different request. I suggest opening a new thread with an appropriate title.
    As per 'removing data', glad having been of some help.

  5. #5
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,744

    Re: Remove Data from rows

    Ok will do. thank you so much

  6. #6
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,744

    Re: Remove Data from rows

    Can you add a message box? " Are you sure you want to delete" with Ok and Cancel.

    Thank you

  7. #7
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    928

    Re: Remove Data from rows

    Add these three lines of code to your macro.
    Option Explicit
    Sub DeleteItems()
        Dim answer As String
        answer = MsgBox("Are you sure you want to delete?", vbYesNo)
        If answer = vbNo Then Exit Sub
        With Sheets("Sheet1").Range("$B3:$H$3000")    '<- use this is for a static range
            'With Sheets("Sheet1").Range("$B3:$H$" & Cells(Rows.Count, "B").End(xlUp).Row) '<- use this instead for a dynamic range
            Sheets("Sheet1").AutoFilterMode = False
            .AutoFilter Field:=7, Criteria1:="YES", Operator:=xlFilterValues
            .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
            Sheets("Sheet1").AutoFilterMode = False
        End With
    End Sub

  8. #8
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,744

    Re: Remove Data from rows

    Hi rollis13

    Ok I did change the code.
    But Why it deletes the filter after I click the macro button? Can you fix it please. (See attachment)

    Thank you
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,744

    Re: Remove Data from rows

    Hi

    Alao please
    maybe instead using Sheet1 if you can change it to activesheet so i can use the same maco button for Sheet2?

    I tried to use the code for sheet2 but it did not work.

    Thank you so much

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

    Re: Remove Data from rows

    .
    Hi. Try with:

    Sub DeleteItems()
    If MsgBox("Are you sure you want to delete?", vbYesNo) = vbNo Then Exit Sub
    With Range("$H3", Cells(Rows.Count, "B").End(xlUp))
      .AutoFilter
      .AutoFilter Field:=7, Criteria1:="YES", Operator:=xlFilterValues
      If WorksheetFunction.Subtotal(3, .Columns(7)) > 1 Then .Offset(1).SpecialCells(12).EntireRow.Delete
      .Parent.ShowAllData
    End With
    End Sub
    Last edited by beyond Excel; 03-24-2023 at 09:59 PM.
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  11. #11
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,744

    Re: Remove Data from rows

    Hi BeyondExcel,

    I have one issue. Please fix.

    I may need to hide a column or columns. Will you be able to fix so that I can hide some columns in the worksheet.

    The sample had hidden column and an error said its overlapping.

    Thank you so much.
    Attached Files Attached Files

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

    Re: Remove Data from rows

    Hello. I saw that you have coded a sheet event.
    So try it this way:

    PHP Code: 
    Sub DeleteItems()
    If 
    MsgBox("Are you sure you want to delete?"vbYesNo) = vbNo Then Exit Sub
    With Range
    ("$H3"Cells(Rows.Count"B").End(xlUp))
      .
    AutoFilter
      
    .AutoFilter Field:=7Criteria1:="YES"Operator:=xlFilterValues
      
    If WorksheetFunction.Subtotal(3, .Columns(7)) > 1 Then
        Application
    .EnableEvents False
          
    .Offset(1).EntireRow.Delete
        Application
    .EnableEvents True
      End 
    If
      .
    Parent.ShowAllData
    End With
    End Sub 

+ 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] Remove rows of data 'not' containing certain criteria
    By sherylt13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-13-2018, 09:30 PM
  2. [SOLVED] Remove Rows from Filtered Data
    By JDmacroman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2015, 09:06 PM
  3. Replies: 3
    Last Post: 05-07-2015, 01:26 PM
  4. remove blanks rows from data
    By bakhtawar in forum Excel General
    Replies: 1
    Last Post: 05-07-2015, 04:47 AM
  5. How to remove rows with data value = 0
    By ajun in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-03-2013, 04:06 AM
  6. Replies: 1
    Last Post: 10-23-2012, 09:12 AM
  7. if only cells in col A, B, C and D contain data, then remove rows
    By VBisgreat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2009, 07:01 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