deleting rows excel

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Deleting rows in Excel

Deleting rows in Excel

resolvedResolved · Low Priority · Version 2016

Ian has attended:
Excel VBA Introduction course
Excel VBA Intermediate course

Deleting rows in Excel

I want some code to look at three cells in the row below. If the active cell and the cell 7 columns to the left are blank then delete that row.
If the cell is column -8 is also blank then stop the loop (as we have reached the end of the data)
Error message of having a loop without a do, but I appear to have a do. Thank you for your help
PS I am a novice coder

Sub clearblanklines()
Do Until ActiveCell.Offset(1, 0).Value = ("") And ActiveCell.Offset(1, -7).Value = ("") And ActiveCell.Offset(1, -8).Value = ("")
If ActiveCell.Value = ("") And ActiveCell.Offset(0, -7).Value = ("") Then
Rows(ActiveCell.Offset(1, 0).Row).EntireRow.Delete

Else
ActiveCell.Offset(1, 0).Select
Loop

End Sub

RE: deleting rows in Excel

I have a solution that delivers what I need. Please see below. I still don't understand what I am doing wrong with the code in my original question

Sub clearblanklines2()
' this is to clear out the blank lines
Dim count As Integer
For count = 1 To 300

If ActiveCell.Offset(1, 0).Value = ("") And ActiveCell.Offset(1, -7).Value = ("") Then
Rows(ActiveCell.Offset(1, 0).Row).EntireRow.Delete

Else
ActiveCell.Offset(1, 0).Select
End If
Next count
End Sub

RE: deleting rows in Excel

Hi Ian,

Thank you for the forum question.

The error message of having a loop without a do is because you do not have an End If.

It is not a very helpful error message as you have found out.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Thu 31 May 2018: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Generating simple column charts

1.Select cell range containing data/figures
2. Press F11

View all Excel hints and tips


Server loaded in 0.07 secs.