One Macro Does All

S

scottymelloty

I Have 4 worksheets in a file that i use

Worksheet 1 is where i type all my data

Worksheet 2,3,4 autogenerate data from Worksheet 1

When there are lines in Column D with " v " in them i want the
deleted, i found this code that does it perfectly

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

But it only does it when im in a worksheet , so i have to go into eac
one then run the macro, is it possible that when ive typed my data i
worksheet 1 i can run a similar macro that deletes all the rows with
v " in worksheet 2,3 & 4 all at the same time. Im guessing this i
quite easy but i dont know my way around VB at all. Many Thanks


As an additional thing when worksheets 2,3,4 have there rows deleted
save worksheet 2 as evt_test , worksheet 3 as mkt_test and worksheet
as sel_test all in CSV format, i do all this manually.

Is there a macro that i could run that dleetes my lines as above the
automatically saves these worksheets as described.

Any help is much appreciated, Thanks
 
T

Tom Ogilvy

Sub Multi_Sheet_delete_rows()
Dim i as Long
Dim RowNdx As Long
Dim LastRow As Long
Dim varr(2 to 4) as String
varr(2) = "evt_test.csv"
varr(3) = "mkt_test.csv"
varr(4) = "sel_test.csv"
for i = 1 to 4
worksheets(i).Activate
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
if i > 1 and i < 5 then
activesheet.copy
Application.DisplayAlerts = False
Activeworkbook.SaveAs "C:\Myfolder\" & _
varr(i), FileFormat:=xlCSV
Application.DisplayAlerts = True
ActiveWorkbook.Close SaveChanges:=False
End if
Next i
End Sub
 

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