excel vba delete sheet code example

Example 1: delete rows in excel vba code

Sub DeleteRowswithSpecificValue()
For i = Selection.Rows.Count To 1 Step -1
If Cells(i, 2).Value = "Printer" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
End Sub

Example 2: excel vba delete folder

' Needs to add "Microsoft Scripting Runtime" reference to your file
Sub DeleteFolder(pFolder As String, pDeleteReadOnlyToo As Boolean)
    Dim FSO As New FileSystemObject
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.DeleteFolder pFolder, pDeleteReadOnlyToo
End Sub

Example 3: excel vba delete rows

' Removes 3rd row
ThisWorkbook.Worksheets(1).Rows(3).EntireRow.Delete
' Just clear cells without removing row
ThisWorkbook.Worksheets("Feuil1").Rows(3).Cells.ClearContents

' Removes 3rd row of a range
Range("My_RANGE").Rows(3).EntireRow.Delete

Tags:

Vb Example