excel vba
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

Excel VBA

resolvedResolved · High Priority · Version 2007

replyReply Wed 28 Sep 2011, 16:54Delegate Steve said...

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

For upcoming training course dates see: Pricing & availability

replyReply Fri 30 Sep 2011, 14:37Trainer Mark said...

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

 

Please browse our web site to find out more about
microsoft-excel-training and other Microsoft training courses.

Excel tip:

Page Break Preview in Excel 2010

If you select View then Workbook Views then Page Break Preview, you will be able to view how your Excel spreadsheet will be split across multiple pages when printed. Even better, you can also drag a page break to a new place. Excel will then scale down your entire worksheet to fit the information you want on the pages you want.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard