Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help me write a VBA macro to delete specified rows in Microsoft Excel 1

Status
Not open for further replies.

dddivers

Instructor
Dec 4, 2001
30
US
Can any of you geniuses help? I'm trying to write an Excel macro that will delete every 5th row (or 3rd or 4th....whatever I specify), up to a specifed stopping point, in an Excel workbook. I'm close but no banana. HELP! Thank you!
 
hi,

Is this what you looking for?

Sub ClearRowsColums()
'
'select the whole row
Rows("4:4").Select
'clear contents of the whole row
Selection.ClearContents
'select a range in a row
Range("A8:K8").Select
'clear content of the range
Selection.ClearContents
'select the whole column
Columns("C:C").Select
'clear contents of the whole column
Selection.ClearContents
'select a range in a column
Range("F1:F25").Select
'clear content of the range
Selection.ClearContents
End Sub


Hope this helps
 
Try this. All you need to do is retrieve the input values for the Step and End rows.
Code:
    Dim sTmp As String, iRow As Long
    Dim iStep As Long, iEnd As Long
    Dim i As Long, iRemoved As Long
    
    iStep = 5       'step
    iEnd = 25       'last row
    iRemoved = 0
    
    For i = iStep To iEnd Step iStep
        iRow = i - iRemoved
        Rows(iRow & ":" & iRow).Delete Shift:=xlUp
        iRemoved = iRemoved + 1
    Next i
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top