Runtime error '6' Overflow

Solved
djodjo5700 Posted messages 64 Status Membre -  
djodjo5700 Posted messages 64 Status Membre -
Hello,
I am discovering VBA and for now I am just copying codes that are given to me.
My problem is as follows:
I would like to enter a postal code in a box and be able to select a city. The code I was given works on a short list of postal codes and cities, but if I enter all the postal codes of France, I get the following error message:
"Run-time error '6' Overflow".

Could you help me? I am sending you a model of my project MP"1234"

Private Sub Textbox6_Change() 'based on code by Michel_m Dim Tablo Dim letter As String, test As String Dim cptr As Integer, cptr_tablo As Integer, derLig As Integer letter = UCase(TextBox6.Value) If letter = "" Then Exit Sub ReDim Tablo(0) ListboxVilles.Clear derLig = Sheets("CP").Range("A" & Rows.Count).End(xlUp).Row With Sheets("CP") For cptr = 1 To derLig test = .Cells(cptr, 1) If .Cells(cptr, 1) Like letter & "*" Then Tablo(cptr_tablo) = .Cells(cptr, 2) cptr_tablo = cptr_tablo + 1 ReDim Preserve Tablo(cptr_tablo) End If Next End With For cptr_tablo = LBound(Tablo) To UBound(Tablo) ListboxVilles.AddItem Tablo(cptr_tablo) Next End Sub

Best regards,

Jean-Marie

Configuration: Windows / Firefox 33.0

3 réponses

Gyrus Posted messages 3360 Status Membre 526
 
Hello,

An integer type number cannot exceed 32,767.
If you count all the municipalities in France, you exceed this capacity (36,600 municipalities).

Try again after modifying this line of code:
Dim cptr As Long, cptr_tablo As Long, DerLig As Long


See you!
0