AllExperts > Experts 
Search      

VB Script

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Miguel Zapico
Expertise
I can answer question about how to use scripts to consolidate data, connect different systems and automate tasks. I have no experience on using VBScript on web programming.

Experience
I have been using VBScript and Windows Scripting Host as my swiss tool for the last 6 years.

Organizations
New York PC users group (NYPC)
Independant Computer Consultants Association (ICCA)

Education/Credentials
Microsoft MCSE in Windows NT

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > select the last 3 rows in excel

Topic: VB Script



Expert: Miguel Zapico
Date: 6/19/2006
Subject: select the last 3 rows in excel

Question
I need to know how to select the last three rows in an excel workbook so they can be deleted in a macro.  The problem I have is that the last 3 rows will not always be on the same row number?

Any Ideas?   Thanks

Answer
You may use the currentrange property, with a code like this:
sub Delete3Rows()
   Dim myRange As Range
   Dim i
   
   Set myRange = Worksheets("Sheet1").Range("A1").CurrentRegion
   i = myRange.Rows.Count
   Rows(i - 2 & ":" & i).Delete
End sub

This code selects all the region with data around A1 on Sheet1, and deletes the 3 last rows.  To make it work in the worksheet you need, change the worksheet("Sheet1") part.

Hope this helps,
Miguel.

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.