+ Reply to Thread
Results 1 to 11 of 11

Code deletes entire Row, not only a part of it.

Hybrid View

  1. #1
    Registered User
    Join Date
    08-24-2022
    Location
    Spain
    MS-Off Ver
    2010
    Posts
    8

    Code deletes entire Row, not only a part of it.

    Hy!!

    I have a macro that applies a filter for cells with date, selects the visible cells, and deletes them.
    The issue I have is that it deletes the entire Row not only the ones between Q:W
    Below the Rows I want to delete I have other data that I wish to also maintain.

    This is the code I use:

    Sub Clean_Breaks()
    Range("Q14:W231").Select
    Selection.AutoFilter

    Range("Q17").Select
    ActiveSheet.Range("$Q$14:$W$23").AutoFilter Field:=1, Criteria1:= _
    ">01/01/2022", Operator:=xlAnd
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.EntireRow.Delete
    ActiveSheet.ShowAllData
    Selection.AutoFilter

    Range("Q15").Select

    End Sub

    I attach a sample.

    Thank you very much for your help.Forum_Breaks_Delete.xlsm

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Code deletes entire Row, not only a part of it.

    The middle word is the clue:
     Selection.EntireRow.Delete
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    08-24-2022
    Location
    Spain
    MS-Off Ver
    2010
    Posts
    8

    Re: Code deletes entire Row, not only a part of it.

    Thank you!

    If I say just "Selection. Delete" it doesn?t work, because it selects as visual cells the entire row. If I include in the Macro "hide the columns A:P before selecting", it still selects them as visual data.

    What would be the code for selecting the filtered data, (between Q and W, starting with Q17 till the last filtered data, and not affecting columns A:P, nor the rows below Q17:W... that are not filtered) and delete shift up?

    I appreciate your help.

    I don?t know much about VBA. I?m learning while doing and with YouTube videos, but I don?t find this part.

    Thank you a lot.

    Kind regards.
    Last edited by Renta; 09-05-2022 at 05:03 AM.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Code deletes entire Row, not only a part of it.

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Code deletes entire Row, not only a part of it.

    I am no VBA expert, but.


    "Selection. Delete"

    You used a space after the dot.

    Remove the space and try again.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  6. #6
    Registered User
    Join Date
    08-24-2022
    Location
    Spain
    MS-Off Ver
    2010
    Posts
    8

    Re: Code deletes entire Row, not only a part of it.

    Hello, oeldere

    In the code, it is written without space, and it doesn?t work because of the selection. When I ask it to select the visible data from the filter, it selects that part but includes the hole Row too. So, when I say (delete), it deletes the selected part.

    My issue is selecting the adequate cells to be deleted.

    I have tried with "Dim", but I?m doing some mistakes too.

    Thank you a lot!

    _____________________
    My language is not English either. I hope I am explaining well.
    Last edited by Renta; 09-05-2022 at 05:52 AM.

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Code deletes entire Row, not only a part of it.

    Then follow TMS advice "Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file."

  8. #8
    Registered User
    Join Date
    08-24-2022
    Location
    Spain
    MS-Off Ver
    2010
    Posts
    8

    Re: Code deletes entire Row, not only a part of it.

    In my first post, there is an attached file with my Excel. I include a picture of it in this poste too.

    TMS kindly says that that's the clue, but I don?t have the solution to solve it. It should work with "Selection.Delete Shift:=xlUp", but, because it is applied to the wrong selection, it?s not working.

    Thank?s a lot, again!!

    Attachment 794860
    Last edited by Renta; 09-05-2022 at 06:27 AM.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Code deletes entire Row, not only a part of it.

    Missed the attachment

    Note: ' requires the "My Notes" cell to be NAMED as MyNotes
    This is, initially, cell Q19. It will move as entries are added and is used to count the rows.


    Sub BREAK_START()
    '
    ' BREAK_START Macro
    '
    ' Works OK
    
        Range("Q15").Value = Date
        Range("R15").Value = "My name"
        Range("S15").Value = "XY"
        Range("T15").Value = Format(Now, "hh:mm")
        Range("W15").Value = "Break"
        Range("V15").Formula = "=IF((IF(+(RC[-1]-RC[-2])=0,""time.."",RC[-1]-RC[-2]))<0,""St>En!"",IF(+(RC[-1]-RC[-2])=0,""St=En!"",RC[-1]-RC[-2]))"
        
        Range("U15").Select
        
    End Sub
    Sub WC_START()
    '
    ' BREAK_START Macro
    '
    ' Works OK
    
        Range("Q15").Value = Date
        Range("R15").Value = "My name"
        Range("S15").Value = "XY"
        Range("T15").Value = Format(Now, "hh:mm")
        Range("W15").Value = "WC"
        Range("V15").Formula = "=IF((IF(+(RC[-1]-RC[-2])=0,""time.."",RC[-1]-RC[-2]))<0,""St>En!"",IF(+(RC[-1]-RC[-2])=0,""St=En!"",RC[-1]-RC[-2]))"
        
        Range("U15").Select
        
    End Sub
    
    Sub BREAK_END()
    '
    ' BREAK_END Macro
    '
    ' Works OK
    
    If Range("T15") = "" Then
        MsgBox "Write the START hour first, please."
    Else
        Range("U15").Value = Format(Now, "hh:mm")
        Range("Q15:W15").Copy Range("Q16")
        Range("Q16:W16").Insert shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("V16:V17").Locked = False
        Range("V16:V17").FormulaHidden = True
        Range("Q15:U15").ClearContents
        Range("W15").ClearContents
        
        Range("U17").Select
    End If
    
    End Sub
    Sub Clean_Breaks()
    '
    ' Clean_Breaks Macro
    '
    
    ' requires the "My Notes" cell to be NAMED as MyNotes
    Dim lLR As Long
    Dim wsf As WorksheetFunction: Set wsf = WorksheetFunction
        
    lLR = Range("MyNotes").Row - 1
    lrows = wsf.Count(Range(Cells(17, "Q"), Cells(lLR, "Q")))
    If lrows >= 1 Then
        Range("Q17").Resize(lrows, 7).Delete shift:=xlUp
    End If
        
        Range("Q15").Select
    End Sub
    
    Sub BREAKE_COPY()
    '
    ' BREAKE_COPY Macro
    '
    
    ' requires the "My Notes" cell to be NAMED as MyNotes
    Dim lLR As Long
    Dim wsf As WorksheetFunction: Set wsf = WorksheetFunction
        
    lLR = Range("MyNotes").Row - 1
    lrows = wsf.Count(Range(Cells(17, "Q"), Cells(lLR, "Q")))
    If lrows >= 1 Then
        Range("Q17").Resize(lrows, 7).Copy
    End If
    
    End Sub

  10. #10
    Registered User
    Join Date
    08-24-2022
    Location
    Spain
    MS-Off Ver
    2010
    Posts
    8

    Re: Code deletes entire Row, not only a part of it.

    It works!!! It works!!! It works!!!!!!!

    Thanks a lot TMS for not quitting on me. You made my day!!!

    Thank you too oeldere for trying!!

    I'm all a smile now.

    Have a wonderful, wonderful day!!
    Last edited by Renta; 09-06-2022 at 06:42 AM.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Code deletes entire Row, not only a part of it.

    You're welcome. Thanks for the 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. Issue - Single character deletes your entire post.
    By martix in forum Suggestions for Improvement
    Replies: 13
    Last Post: 01-07-2020, 12:41 PM
  2. [SOLVED] Find and Replace value deletes entire cell contents
    By patb in forum Excel General
    Replies: 5
    Last Post: 09-25-2018, 10:27 AM
  3. VBA that deletes entire rows if value is NOT found in part
    By Andrewstupendo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-21-2018, 03:01 PM
  4. [SOLVED] vba code that deletes entire row if there is a zero in that row of my highlighted area
    By gt4udish in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2015, 03:39 AM
  5. [SOLVED] VBA that looks up a string (or part of) value and deletes the cell
    By gaia in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-19-2013, 05:33 AM
  6. Creating Excel Macro That Deletes Entire Row with Specific Text
    By Efar68 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2011, 04:33 AM
  7. Useful code that deletes entire rows based on formatting
    By Ralfie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2007, 01:02 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