Macros in Excel

Hajduk1908

New Member
Joined
Aug 16, 2015
Messages
13
Hello I have a macro that loops through selected worksheets in my workbook, deletes the top ten rows and exports it as a CSV. The macro button is on separate worksheet called Monday however I would look like the macro to ignore this worksheet called Monday as this is my control worksheet,
I have tried a few things but unable to get it to work.

Sub Test_loop()

ActiveWorkbook.Save

Dim ws As Worksheet
Dim path As String

path = ActiveWorkbook.path & "\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)

' Loop through all selected sheets.
For Each ws In ActiveWindow.SelectedSheets

ws.Rows("1:10").Delete ' Delete 10 rows at top of each sheet.
ws.Copy

Range("A1").Interior.Color = 1 ' Format A1 so the top rows are included in the used range and saved
ActiveWorkbook.SaveAs Filename:=path & "_" & ws.Name & ".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close SaveChanges = False

Next ws

End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Please try this code if it works.
Code:
Sub Test_loop()

ActiveWorkbook.Save

Dim ws As Worksheet
Dim path As String

path = ActiveWorkbook.path & "\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)

' Loop through all selected sheets.
For Each ws In ActiveWindow.SelectedSheets

IF ws.name <> "Monday" then
ws.Rows("1:10").Delete ' Delete 10 rows at top of each sheet.
ws.Copy

Range("A1").Interior.Color = 1 ' Format A1 so the top rows are included in the used range and saved
ActiveWorkbook.SaveAs Filename:=path & "_" & ws.Name & ".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close SaveChanges = False


End IF
Next ws

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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