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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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

tuytuy

Board Regular
Joined
Mar 28, 2013
Messages
75
ADVERTISEMENT
still doesn't work :/ nothing happens.
Is this bit correct ?

Code:
ws.Rows(1).Delete
 
Upvote 0

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Office Version
  1. 365
Platform
  1. Windows
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

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,154
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,807
Office Version
  1. 365
Platform
  1. Windows
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,195,589
Messages
6,010,609
Members
441,558
Latest member
lambierules

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
Top