seekyourway
New Member
- Joined
- Nov 1, 2011
- Messages
- 21
Hello,
I just wanted to delete all rows in a worksheet. The macro doesn't give any error, but it's not deleting. It seems to be shifting rows as it loops. This is what I have:
Dim wB As Workbook
Dim wS As Worksheet
Dim lastRow As Integer
Dim j As Integer
'On Error GoTo ErrHandler
Application.ScreenUpdating = True
'Delete existing records in template
Workbooks.Open HosTemplate
Set wB = ActiveWorkbook
Set wS = ActiveWorkbook.Worksheets("data")
With wS
lastRows = .UsedRange.Rows.Count
For j = 2 To lastRows
.Rows(j).Delete
Next j
End With
wB.Save
wB.Close
Thank you for helping
I just wanted to delete all rows in a worksheet. The macro doesn't give any error, but it's not deleting. It seems to be shifting rows as it loops. This is what I have:
Dim wB As Workbook
Dim wS As Worksheet
Dim lastRow As Integer
Dim j As Integer
'On Error GoTo ErrHandler
Application.ScreenUpdating = True
'Delete existing records in template
Workbooks.Open HosTemplate
Set wB = ActiveWorkbook
Set wS = ActiveWorkbook.Worksheets("data")
With wS
lastRows = .UsedRange.Rows.Count
For j = 2 To lastRows
.Rows(j).Delete
Next j
End With
wB.Save
wB.Close
Thank you for helping