Delete Rows

S

scottymelloty

Sub delete_rows()
Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "D").Value = " v " Then
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub


This code deletes rows with " v " in Column D but only does it on th
sheet i am in when i run it, how do i get it to go through all th
sheets in the workbook to check for " v " and delete them as well.

Many Thank
 
F

Frank Kabel

Hi
try:
Sub delete_rows()
Dim RowNdx As Long
Dim LastRow As Long
dim wks as worksheet

application.screenupdating=false
for eack wks in worksheets
LastRow = wks .Cells(Rows.Count, "D").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "D").Value = " v " Then
Rows(RowNdx).Delete
End If
Next RowNdx
next wks
application.screenupdating=true
End Sub
 
G

Guest

Here is a loop that will go through each worksheet in the active workbook.
You just have to run your code within the loop.

Sub RunThroughAllSheets
Dim ws As Worksheet

For Each ws In Worksheets
ws.Activate
'insert your code here *****************************
'display the name of the active sheet
MsgBox (ws.Name)
'insert your code here *****************************
Next
end sub

Hope this helps

Jenny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top