?
Solved

Overflow Message

Posted on 2011-03-03
3
Medium Priority
?
320 Views
Last Modified: 2012-05-11
I am using the code below, tied to a command button.

The code autofits my columns and then enters a total line at the bottom of the data.

This is exported data, so the amount of rows varies each time.

This was working, but it is now giving an runtime error 6  'overflow' message at this line (line 21 below):

 rows_in_col = Range(cell, cell.End(xlDown)).Count

Any help appreciated- thanks!

Sub DoTasks()


 Dim cell As Range
    Dim total As Integer
    Dim rows_in_col As Integer
    
    Dim header As Range
    
    'Find cells in header
    If Range("F5") = "" Then
        'May only be one cell in header
        Set header = Range("E5")
    Else
        Set header = Range(Range("F5"), Range("F5").End(xlToRight))
    End If
    
    
    'Find the max row
    For Each cell In header
        rows_in_col = Range(cell, cell.End(xlDown)).Count
        If rows_in_col > total Then
            total = rows_in_col
        End If
    Next cell
    
    'Add the sum column two rows below max
    For Each cell In header
        Cells(cell.Row + total + 1, cell.Column).Formula = "=@subtotal(9," & _
            Range(cell, cell.End(xlDown)).Address & ")"
    Next cell
    
    'Same command as double clicking the border.
    Range("A:S").EntireColumn.AutoFit
    
    Cells(header.Row + total + 1, 1).Activate

End Sub

Open in new window

0
Comment
Question by:snyperj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 35027423
Change:
Dim total As Integer
    Dim rows_in_col As Integer

Open in new window

to:
Dim total As Long
    Dim rows_in_col As Long

Open in new window

0
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 35027429

Use this...

Saurabh...
rows_in_col=Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row

Open in new window

0
 

Author Closing Comment

by:snyperj
ID: 35027574
Yes, exactly.  This particular export was 45K rows... so that was the prob.  Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

764 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