V
V
Vladislav B2021-07-21 17:01:06
Visual Basic
Vladislav B, 2021-07-21 17:01:06

Why does Runtime error 6 Overflow occur?

Please help me figure it out. Runtime error '6' Overflow occurs all the time in VBA.
The error occurs in this line "If WBook.Cells(q, 7) = ArrayPhoneAll(i) Then"
The column contains phone numbers or email, if you change the column number, no error occurs.

Sub RegisterComplaintsPhone()

Dim n As Integer
Dim q As Long

n = 1


    
Set WBook = Workbooks("ДС_Реестр жалоб ГЛ и ЧАТ 09.07.2021222.xlsx").Worksheets("ДС_ГЛ, ЧАТ")

ReDim ArrayPhone(n) As Variant       
ReDim ArraySuccess(n) As Variant     
ReDim ArrayResult(n) As Variant      
ReDim ArrayPhone(n) As Variant       
ReDim ArrayFIO(n) As Variant         
ReDim ArrayDS(n) As Variant          
ReDim ArrayEmployee(n) As Variant    
ReDim ArrayEmployeeAll(n) As Variant 
ReDim ArrayDSAll(n) As Variant       
ReDim ArrayPhoneAll(n) As Variant    
ReDim ArrayResultAll(n) As Variant

n = 1
For w = 2 To 300
    If Worksheets("ДС").Cells(w, 2) <> "" Then
        ArrayPhoneAll(n) = Worksheets("ДС").Cells(w, 14).Value
        ArrayEmployeeAll(n) = Worksheets("ДС").Cells(w, 3).Value
        ArrayResultAll(n) = Worksheets("ДС").Cells(w, 2).Value
        Worksheets("ДС").Cells(w, 19) = ArrayPhoneAll(n)
        Worksheets("ДС").Cells(w, 20) = ArrayEmployeeAll(n)
        Worksheets("ДС").Cells(w, 21) = ArrayResultAll(n)
        n = n + 1
        'ReDim Preserve ArrayDSAll(n)
        ReDim Preserve ArrayPhoneAll(n)
        ReDim Preserve ArrayEmployeeAll(n)
        ReDim Preserve ArrayResultAll(n)
    End If
Next

n = 1 

MsgBox ArrayPhoneAll(1)
For i = 1 To UBound(ArrayPhoneAll) - 1
    For q = 2 To 20000
        If WBook.Cells(q, 7) = ArrayPhoneAll(i) Then
            WBook.Cells(q, 31) = ArrayPhoneAll(i)
        End If
    Next
Next
End Sub

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BasiC2k, 2021-07-21
@BasiC2k

When accessing a value in Cells, always specify the Value property. So:
If WBook.Cells(q, 7).Value = ArrayPhoneAll(i) Then
Also keep in mind that one of the compared values ​​can be Nothing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question