Solved

Overflow Message

Posted on 2011-03-03
3
317 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
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

792 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