Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Overflow Message

Posted on 2011-03-03
3
Medium Priority
?
323 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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 …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

610 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