excel vba

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 » Excel VBA

Excel VBA

resolvedResolved · High Priority · Version 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:

The Easiest and Quickest Way to use Autosum in Excel 2010

Autosum is used frequently in Excel. As with almost every feature of Excel, there are more ways than one to use each feature. Below is the simplest way to use the Autosum feature.

1) Go to the bottom of the column of data.

2) Shortcut click in the column then Ctrl + down arrow

3) Use Alt + = for Autosum and press the enter key to complete.

View all Excel hints and tips


Server loaded in 0.09 secs.