Overflow and variable issues. Please help me print to a table.

pawest

Board Regular
Joined
Jun 27, 2011
Messages
105
The overflow issues has been posted about before but I can't solve it as it relates to my code. Could someone please help me print data to a table without any overflow/variable issues?

Code:
Sub PrintDataTable()

'General variables
Dim symCell
Dim rngCell

Dim dateVal
Dim volVal
Dim symbol As String
Dim lastDataRow As Integer
Dim rng As Range

Sheets("BB Prod Data").Activate

For Each symCell In Sheets("Prod Data").Range("A1:DZU1")
    
    Sheets("Prod Data").Activate
    
    If symCell <> "" Then

        symbol = symCell.Text
        
        With Sheets("Prod Data")
            Set rng = .Range(.Cells(symCell.Offset(3, 0).Row, symCell.Column), .Cells(symCell.End(xlDown).Row, symCell.Column))
        End With
                
        For Each rngCell In rng
            
            dateVal = rngCell.Value
            volVal = rngCell.Offset(0, 1).Value
            
            Sheets("DataTable").Activate
                    
            lastDataRow = Sheets("DataTable").Range("B1040000").End(xlUp).Row
                    
            Sheets("DataTable").Range("B" & lastDataRow + 1).Value = symbol
            Sheets("DataTable").Range("C" & lastDataRow + 1).Value = dateVal
            Sheets("DataTable").Range("D" & lastDataRow + 1).Value = volVal
            
            'Sheets("Prod Data").Activate
 
        Next rngCell
        
    End If

Next symCell

Debug.Print "DONE"

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Dim lastDataRow As Integer
Do you have more than 32768 rows of data? If so, the above declaration is guaranteed to overflow. Try Dim'ming that variable as Long and see if that stops the error. For your future programming efforts, on today's modern computers, there is no reason to use Integer data type as there is no savings in doing so... I would recommend always using Long instead (and Double instead of Single as well)... there are exceptions to this rule, but I doubt you will ever run into them (Windows API function calls and other's functions using ByRef arguments typed as Integer are two that come to mind).
 
Upvote 0
The first thing you need to do is change Integer to Long when declaring lastDataRow.
Code:
Dim lastDataRow As Long
Do that and try the code again.
 
Upvote 0
What a rookie mistake. This worked.

I haven't been programming in VBA lately. I've been doing some work with Perl. I come back to VBA and know nothing!

Thanks Rick and Norie!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top