Solved

Overflow Message

Posted on 2011-03-03
3
314 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

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

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

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

11 Experts available now in Live!

Get 1:1 Help Now