How erase the lines in a table if the meet the following conditions.

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
380
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

Before me I have a table that is called "Locaties". In that table I have the column H, I and J that should always be filled. Now I want to achieve is that when I push a button alle the lines will be erases if either H,I or J is not filled. So they always need to be filled, all 3 of them.
This table starts with the headers on line 5.

Is it possible to do this? Thank you for your time,

Romano

Locatie overslag 1.57u.xlsm
ABCDEFGHIJ
5ArtikelcodeOmschrijvingKostprijsVrrdrekMagazijnLocatieVoorraadvan Locatienaar LocatieAantal
6100000Vito Glaserfix 111 6x2 mm wit - 10x25 m6,7039011P02B 1331P02B 1331
7100001Vito Glaserfix 111 6x2 mm zwart - 10x25 m6,7039011P04B 1060P04B 1060
8100002Vito Glaserfix 111 6x3 mm wit - 10x25 m7,3139011P02B 790P02B B00790
9100003Vito Glaserfix 111 6x3 mm zwart - 10x25 m7,3139011P04B 400P04B 400
10100004Vito Glaserfix 111 6x4 mm wit - 10x25 m9,8939011P02C 600P02C B00600
Boekingen
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try this:
VBA Code:
Sub MyDeleteRows()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows backwards, up to row 6
    For r = lr To 6 Step -1
'       See if columns H, I, or J is empty
        If (Cells(r, "H") = "") Or (Cells(r, "I") = "") Or (Cells(r, "J") = "") Then
'           Delete row
            Rows(r).Delete
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
Try this:
VBA Code:
Sub MyDeleteRows()

    Dim lr As Long
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
   
'   Loop through all rows backwards, up to row 6
    For r = lr To 6 Step -1
'       See if columns H, I, or J is empty
        If (Cells(r, "H") = "") Or (Cells(r, "I") = "") Or (Cells(r, "J") = "") Then
'           Delete row
            Rows(r).Delete
        End If
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
Exactly what I needed, thank you for your help.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top