Quote Originally Posted by westconn1 View Post
while it is good practice to declare all variables, you should define them at the lowest level (within the procedure) unless you really need to reuse the same variable values in many places

also make it hard for us to see if your variable declaration could be causing a problem
what are top1 - 3 defined as? could they have been changed? do you have any duplicate definitions?
Is there a specific reasong that declaring them at the lowest level is the best option? I pretty much need to use all these variables throughout all subs, so I don't think I have much choice, do I?

Here are all variable declarations:

Code:
'Onderstaande is nodig voor workshete identificatie en useform
Public WerkbladNPO As String                'Zal de naam van het werkblad bevatten met de NPO data
Public WerkbladSA As String                 'Zal de naam van het werkblad bevatten met de Soundaware data
Public WorksheetOutput As String            'Zal de nama van het werkblad bevatten waar de rapportage moet verschijnen
Public SheetExists As Integer               'Gebruikt ind e userform: controleert het bestaan van een worksheet
Public PressedCancel As Integer             'Gebruikt voor de worksheet: controleert of de gebruiker op annuleren heeft gedrukt

'Onderstaande is nodig voor het maken van de tabellen
Public TabelType As Integer                 'Geeft de te maken tabel aan. 1 is jaar, 2 is maand, 3 is week
Public Column As Integer                    'Voor het maken van de tabel: de beginkolom
Public Row As Integer                       'Voor het maken van de tabel: de beginrij
Public ColumnEnd As Integer                 'Voor het maken van de tabel: de eindkolom
Public RowEnd As Integer                    'Voor het maken van de tabel: de eindrij

'Onderstaande is nodige voor datum optelling en plaatsing
Public Datum As String                      'De datum, nodig om te herkennen wat opgeteld moet worden
Public Dag As Integer                       'Bevat de dag waarnaar gezocht wordt
Public Maand As Integer                     'Bevat de Maand waarnaar gezocht wordt
Public Jaar As Integer                      'Bevat het jaar waarnaar gezocht wordt.
Public RowNumber As Long                    'Interne variabele: definieert rijnummer waarvandaan gelezen gaat worden.
Public StartCell As Integer                 'Definieert de eerste cel van het bereik dat opgeteld wordt
Public EndCell As Integer                   'Definieert de laatste cel van het bereik dat opgeteld wordt
Public SumResult As Long                    'Houd het resultaat vna de opsomming.
Public WorksheetName As String              'Definieert van welke worksheet gelezen moet worden.
Public ColumnAsString As String             'Definieert de kolom waarin de resultaten gezet zullen worden
Public DatumKolom As String                 'Definieert de kolom waar datum in staat (NPO = AL, SA = AP)
Public DurationKolom As String              'Definieert de kolom waar duration in staat (NPO = AK, SA = AO)

'Onderstaande is nodig om de drie grootste verschillen binnen jaar, maanden en weken te vinden.
Public Top1 As Long                         'Used to find the highest number
Public Top2 As Long                         'Used to find the second highest number
Public Top3 As Long                         'Used to find the third highest number
Public WaardenRegel1 As Long                'Used to find the row on which the highest number is located
Public WaardenRegel2 As Long                'Used to find the row on which the second highest number is located
Public WaardenRegel3 As Long                'Used to find the row on which the third highest number is located

'Onderstaande wordne gebruikt bij het maken van een jaaroverzicht grafiek
Public Grafieken As ChartObject
Public GrafiekTitel As String
Since I'm Dutch, all the comments are in Dutch also. Most of them are irrelevant to the sub I posted, so I only translated the "top1-3" and "Waardenregel1-3" variables. If you need any more I'll be happy to oblige.

I'm still not sure what is causing the error, because the code worked fine before. I tried declaring the variables necessary in the sub itself using Dim instead of Public, but that didn't help. I'm not quite sure what is happening; top1 always becomes "1", subsequently generating an error in the "Waardenregel1" line of code.