1

I am getting run time error 6: Overflow through the below code.

n = (.Cells(Rows.Count, "A").End(xlUp).Row)   
FillP = Array("D", "E", "F", "H", "I", "J", "M", "O", "P", "AR", "AS", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BL", "BQ", "BR", "BS", "BT", "BU", "BV", "BW", "BX", "BY", "CB", "CC", "CD")

'fill blanks with na
For i = 2 To n
    For j = LBound(FillP) To UBound(FillP)
        If Trim(.Range(FillP(j) & i)) = "" Then
            .Range(FillP(j) & i) = "na"
        End If
    Next j
Next i

I have Excel 2010, I haven't yet declared any of the above variables yet (will do after testing). Just trying to fill blanks in specific columns with an "na". Nearly identical code appears earlier in my sub and yet it runs fine. No idea where i'm going wrong.

Thanks in advance for any help!

9
  • Gave that a try, afraid it made no difference. If it helps n = 2650 Commented Oct 27, 2016 at 17:39
  • Which line throws the error? Commented Oct 27, 2016 at 17:40
  • And what are the values of the variables at that time? Commented Oct 27, 2016 at 17:40
  • 1
    Well that would do it. You will need to add another if/then before the current one to test for the error. IF Not IsError(.Range(FillP(j) & i)) Then Commented Oct 27, 2016 at 18:10
  • 1
    @ScottCraner - A Variant will silently promote itself to a Long instead of overflowing as an Integer. In fact, it will silently promote itself to a Double instead of overflowing as a Long. Commented Oct 27, 2016 at 18:43

2 Answers 2

1

overflow results when you try to assign value to a variable, that exceeds the limitations of the data type. I am afraid that you might have declared i, j, or n as Interger.

Also you will not need the dot operator before cells & range.

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

Comments

0

Where does the error specificaally occur? just from inspection, you do not need the dots before Cells and Range. You would only do that in a with statement

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.