Make changes to all worksheets except for 2

skull_eagle

Board Regular
Joined
Mar 25, 2011
Messages
89
Hi,

I have the following code which deletes a column and adds headings to all sheets.

The problem is there are 2 sheets I don't want it to do this to, I've tried to add an array and an if function to protect these sheets but I'm obviously doing something wrong.

<font face=Courier New><SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> currentsheet <SPAN style="color:#00007F">As</SPAN> Worksheet<br> <br><SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> ActiveWorkbook.Worksheets.Count<br><SPAN style="color:#00007F">Set</SPAN> currentsheet = ActiveWorkbook.Worksheets(i)<br>Worksheets(i).Activate<br><SPAN style="color:#007F00">'protectsh = Array("Master Box List", "Review")</SPAN><br><SPAN style="color:#007F00">'If ActiveSheet.Name <> protectsh Then</SPAN><br>****Columns("D:D").Select<br>****Selection.Delete Shift:=xlToLeft<br>****Range("A1").Select<br>****ActiveCell.FormulaR1C1 = "CLIENT NAME"<br>****Range("B1").Select<br>****ActiveCell.FormulaR1C1 = "DATE RANGE"<br>****Range("C1").Select<br>****ActiveCell.FormulaR1C1 = "PARTNER / MANAGER"<br>****Range("D1").Select<br>****ActiveCell.FormulaR1C1 = "BOX NUMBER"<br>****Range("E1").Select<br>****ActiveCell.FormulaR1C1 = "FILE NUMBER"<br>****Range("F1").Select<br>****ActiveCell.FormulaR1C1 = "REVIEW DATE"<br>****Cells.Select<br>****Cells.EntireColumn.AutoFit<br>****Range("A1").Select<br><br><SPAN style="color:#007F00">'End If</SPAN><br><SPAN style="color:#00007F">Next</SPAN> i<br>Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN></FONT>

Any help would be greatly appreciated.


Thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi

Assuming the macro does what you want (apart from skipping the 2 sheets) then you just need to check at each iteration if the sheet's name is one to be excluded (ie with an If statement) and skip on to the next sheet if so:

Code:
Dim i As Integer
Dim currentsheet As Worksheet

For i = 1 To ActiveWorkbook.Worksheets.Count
If Not (Worksheets(i).Name = "Master Box Lists" Or WOrksheets(i).Name = "Review") Then
  'Set currentsheet = ActiveWorkbook.Worksheets(i)
  Worksheets(i).Activate
  'protectsh = Array("Master Box List", "Review")
  'If ActiveSheet.Name <> protectsh Then
  Columns("D:D").Select
   Selection.Delete Shift:=xlToLeft
   Range("A1").Select
   ActiveCell.FormulaR1C1 = "CLIENT NAME"
   Range("B1").Select
     ActiveCell.FormulaR1C1 = "DATE RANGE"
     Range("C1").Select
     ActiveCell.FormulaR1C1 = "PARTNER / MANAGER"
     Range("D1").Select
     ActiveCell.FormulaR1C1 = "BOX NUMBER"
     Range("E1").Select
     ActiveCell.FormulaR1C1 = "FILE NUMBER"
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "REVIEW DATE"
     Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A1").Select

End If
Next i
Application.ScreenUpdating = True
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,761
Members
452,940
Latest member
rootytrip

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