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

excel vba

ResolvedVersion 2007

Steve has attended:
Excel VBA Intro Intermediate course

Excel VBA

I trying to delete all rows based on the current region property starting in cell A12. The number of rows is not fixed and will vary each time. I have written the following code:

Dim WorkRange As Range
Dim Row As Range
Dim i As Variant

Sheets("Summary P&L Report").Activate
Set WorkRange = Sheets("Summary P&L Report").Range("A12").CurrentRegion

For i = WorkRange.Rows.Count To 1 Step -1
Set Row = WorkRange.Rows(i)

If Sheets("Summary P&L Report").Range ("A12").Cells.Value = "A" Then
Row.Delete

End If

Next i

Is the above the most efficient way to delete. Secondly I don't really want it to be conditional on range A12. I just want all rows (no matter how many there are) from A12 down to be deleted.

Many thanks

Steve

RE: Excel VBA

Hello Steve,

Not sure what you really need, but another way of deleting a selection is as follows:

Range("A12").CurrentRegion.Select
Selection.Delete

this will select the whole region and delete, this will save on the looping and deleting one row at a time! Maybe that is what you need?

I hope this resolves your question. If it has, please mark this question as resolved.

If you require further assistance, please reply to this post. Or perhaps you have another Microsoft Office question?

Have a great day.
Regards,

Mark
Microsoft Office Specialist Trainer

 

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:

Shortcut keys to move between sheets

Instead of clicking on a sheet tab to view a sheet, use the following keyboard shortcuts to move between sheets in the same file:

Ctrl + Page Down - Switch to the next worksheet (to the right)

Ctrl + Page Up - Switch to the previous worksheet (to the left)

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.