Solved

Overflow Message

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

695 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