macro vba delete first row of all sheets except some

tuytuy

Board Regular
Joined
Mar 28, 2013
Messages
75
Hi,
i wanted to right a vba that would delete the first row all all the sheets except 3 ("SynthesisVSD" And "BlackBerry" And "Table_Of_Content")

Here is what i wrote but i get a type mismatch:

Code:
'Deleting first row


For Each Worksheet In ThisWorkbook.Worksheets
Namews = Array("SynthesisVSD", _
              "BlackBerry", _
              "Table_Of_Content")
If Worksheet.Name = Namews Then
            With Worksheet.UsedRange
                Worksheet.Rows(1).Delete
            End With
        End If


Next
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try

Code:
'Deleting first row

namews = Array("SynthesisVSD", _
              "BlackBerry", _
              "Table_Of_Content")

For Each ws In ThisWorkbook.Worksheets
    If IsError(Application.Match(ws.Name, namews, 0)) Then ws.Rows (1), Delete
Next ws
 
Upvote 0
Typo

Rich (BB code):
'Deleting first row

namews = Array("SynthesisVSD", _
              "BlackBerry", _
              "Table_Of_Content")

For Each ws In ThisWorkbook.Worksheets
    If IsError(Application.Match(ws.Name, namews, 0)) Then ws.Rows(1).Delete
Next ws
 
Upvote 0
try below one
Code:
Sub Test()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "SynthesisVSD" And ws.Name <> "BlackBerry" And ws.Name <> "Table_Of_Content" Then ws.Rows(1).Delete
Next ws
End Sub
 
Upvote 0
Here is another macro you can try...
Code:
Sub DeleteFirstRowCertainSheets()
  Dim WS As Worksheet
  For Each WS In ThisWorkbook.Worksheets
    If InStr(1, "/SynthesisVSD/BlackBerry/Table_Of_Content/", "/" & _
         WS.Name & "/", vbTextCompare) = 0 Then WS.Rows(1).Delete
  Next
End Sub
 
Upvote 0
Yet another possibility
Code:
Sub Delete_Row()
  Dim ws As Worksheet
  
  For Each ws In Worksheets
    Select Case ws.Name
      Case "SynthesisVSD", "BlackBerry", "Table_Of_Content" '<- Add more if you want
      Case Else
        ws.Rows(1).Delete
    End Select
  Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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