1

I am trying to run a macro. The macro looks in each row in column A and if the value is greater than 0 it will copy a range of cells from the same row (M:BT) and paste and transpose that range in the cell in column K of the same row. The code below works but the number of rows change and can be a lot. I need it to loop through until no more data can be found in column A. Keep in mind there will be empty rows. As I said before my code works with a small sample 100 rows but when I did one for like 65,000 rows it give me an

Overflow error

Any ideas how to fix this?

Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+w
'
Range("K1").Select
ActiveCell.FormulaR1C1 = "DATE"
Range("L1").Select
ActiveCell.FormulaR1C1 = "DAYS"
Columns("BU:EB").Select
Selection.Delete Shift:=xlToLeft
Columns("EC:IR").Select
Selection.Delete Shift:=xlToLeft
With ActiveSheet
    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

Dim AddRows As Integer: AddRows = 59

Dim i As Integer: i = lastrow

Do While i <> 1
    Rows(i & ":" & i + AddRows - 1).Insert
    i = i - 1
Loop

ScreenUpdating = True
Rows("2:60").Select
Selection.Delete Shift:=xlUp
Range("A1").Select

Dim x As Integer, a As Integer
a = Cells(Rows.Count, 1).End(xlUp).Row

For x = 2 To a
If Cells(i, 1) > 0 Then
Range(Cells(x, 13), Cells(x, 72)).Select
Selection.Copy
Cells(x, 11).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=True, Transpose:=True
End If
Next x
End Sub

1 Answer 1

2

Integers are not "big enough" to hold your large number. Use Long instead of Integer.

Dim x As Long, a As Long

See https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/data-type-summary Integer data type is signed 2 bytes and can therefore only hold from -32768 to + 32767

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.