Repetitive actions done sequentially across
ROWS
COLUMNS
Sheets
Books
Sequentially designated Ranges
All of these (and more) benefit from a FOR / NEXT loop. Read up on them.
http://www.anthony-vba.kefra.com/vba...oop_Structures
http://exceltip.com/st/Using_Loops_i...Excel/628.html (Exercise 6)
Example:
Sub DeleteAllPictures()
Dim DrObj, Pic
Set DrObj = ActiveSheet.DrawingObjects
'ActiveSheet.Protect UserInterfaceOnly:=True 'Optional
For Each Pic In DrObj
If Left(Pic.Name, 7) = "Picture" Then Pic.Delete
Next
End Sub
This repetitively evaluates the name of every object in a sheet, if it's a "picture", it deletes it.
Another:
Sub DeleteErrorB()
Dim i As Integer, lastrow As Long
Application.ScreenUpdating = False
lastrow = Range("A" & Rows.Count).End(xlUp).Row
For i = lastrow To 1 Step -1
If WorksheetFunction.IsError(Cells(i, 2)) Then Rows(i).EntireRow.Delete (xlShiftUp)
Next i
Application.ScreenUpdating = True
End Sub
This repetitively check the value in column B for each row in a data set, deletes the rows that have error values.
Bookmarks