Edit Macro to Hide not Delete

Alex O

Active Member
Joined
Mar 16, 2009
Messages
345
Office Version
  1. 365
Platform
  1. Windows
Can my macro below be edited to hide the target rows insted of deleting them?

Thanks

Sub DeleteUnwantedRows()
Dim iLastRow As Long
Dim i As Long
iLastRow = Cells(Rows.Count, "M").End(xlUp).Row
For i = iLastRow To 11 Step -1

If Cells(i, "M").Value <> "117" _
And Cells(i, "M").Value <> "119" _
And Cells(i, "M").Value <> "120" _
And Cells(i, "M").Value <> "121" _
And Cells(i, "M").Value <> "122" _
Then
Rows(i).EntireRow.Delete
End If
Next i

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try

Rich (BB code):
Sub DeleteUnwantedRows()
Dim iLastRow As Long
Dim i As Long
iLastRow = Cells(Rows.Count, "M").End(xlUp).Row
For i = iLastRow To 11 Step -1

If Cells(i, "M").Value <> "117" _
And Cells(i, "M").Value <> "119" _
And Cells(i, "M").Value <> "120" _
And Cells(i, "M").Value <> "121" _
And Cells(i, "M").Value <> "122" _
Then
Rows(i).Hidden = True
End If
Next i

End Sub
 
Upvote 0
Can my macro below be edited to hide the target rows insted of deleting them?

Thanks

Sub DeleteUnwantedRows()
Dim iLastRow As Long
Dim i As Long
iLastRow = Cells(Rows.Count, "M").End(xlUp).Row
For i = iLastRow To 11 Step -1

If Cells(i, "M").Value <> "117" _
And Cells(i, "M").Value <> "119" _
And Cells(i, "M").Value <> "120" _
And Cells(i, "M").Value <> "121" _
And Cells(i, "M").Value <> "122" _
Then
Rows(i).EntireRow.Delete
End If
Next i

End Sub

Try this

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DeleteUnwantedRows()<br><SPAN style="color:#00007F">Dim</SPAN> iLastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>iLastRow = Cells(Rows.Count, "M").End(xlUp).Row<br><SPAN style="color:#00007F">For</SPAN> i = iLastRow <SPAN style="color:#00007F">To</SPAN> 11 <SPAN style="color:#00007F">Step</SPAN> -1<br><br><SPAN style="color:#00007F">If</SPAN> Cells(i, "M").Value <> "117" _<br>And Cells(i, "M").Value <> "119" _<br>And Cells(i, "M").Value <> "120" _<br>And Cells(i, "M").Value <> "121" _<br>And Cells(i, "M").Value <> "122" _<br>Then<br>Rows(i).EntireRow.Hidden = <SPAN style="color:#00007F">True</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">Next</SPAN> i<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
As always, the assistance is appreciated! Problem solved
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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