Solved

VBA Function for finding Excel maxrows

Posted on 2012-03-29
8
269 Views
Last Modified: 2012-03-30
I am trying to figure out how to test the version number/type of a workbook and then return what the maximum number of rows that workbook can take using a function in VBA.  Does such a thing exist?
0
Comment
Question by:simonwait
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 37784144
activesheet.rows.count

will give you the rows in the active sheet.
0
 
LVL 39

Expert Comment

by:Kyle Abrahams
ID: 37784174
http://www.mrexcel.com/forum/showthread.php?t=357733

dim MaxRows as int
if application.version >= 12.0 then
     'code goes here
MaxRows = 1048576
else
   maxRows = 65536
 end if

http://vbadud.blogspot.com/2010/02/maximum-limit-of-rows-columns-etc-in.html
0
 
LVL 1

Author Comment

by:simonwait
ID: 37784183
Thanks, what I needed to check was the maximum number of rows I could use before the excel limits for that version kicked in (ie Excel 2010 = 1,048,576 lines but 97 is 16,384).  I figured out a way but it may not be accurate?  Any thoughts?
excelver = ActiveWorkbook.FileFormat
Select Case excelver
Case 50 Or 51 Or 52
excelmaxrows = 1048576
Case 56
excelmaxrows = 65536
Case Else
excelmaxrows = 16384
End Select

Open in new window

0
 
LVL 1

Author Comment

by:simonwait
ID: 37784189
Thanks for that ged325 but what if I am looking at a 2003 xls on Excel 2010?  wouldnt that show as 1048576 rows were possible not 65536?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 37784198
You do not need all that. Simply

Sheets("Sheet1").rows.count

will give the number of rows in that sheet.
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 37784317
As Saqib says you can use ActiveSheet.Rows.Count, or you can use Application.Rows.Count, which will return the higher or lower number depending on the capabilities of the active workbook.  You should always use these properties rather than literals - who knows what the limit will be in the next version of Excel - some time it will go up to 2,147,483,648!
0
 
LVL 39

Expert Comment

by:Kyle Abrahams
ID: 37784390
I forgot about the rows.count function . . . that's the most efficient and guaranteed to return the correct number every time . . . most likely the best way to go.
0
 
LVL 1

Author Comment

by:simonwait
ID: 37785997
Ah sorry, thats the trouble with assumption!  I assumed that it was the same as activesheet.usedrange.rows.count.  Should have stopped and thought...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now