'find the cell where to start writing opening the existing file (and reading the number of cell where to start):
Dim foglioExcel2 As Excel.Worksheet
foglioExcel2 = cartExcel.Worksheets.Item(2)
conteggio = foglioExcel2.Cells(2, 4).value
If conteggio <> 0 Then
contoriga = foglioExcel2.Cells(2, 4).value
End If
'writing data on excel file:
foglioExcel2.Range("A2").EntireColumn.WrapText = True
foglioExcel2.Cells(contoriga, 1).value = domande(random)
foglioExcel2.Cells(contoriga, 2).value = UCase(scelta)
foglioExcel2.Cells(2, 4).value = contoriga
contogiuste = foglioExcel2.Cells(2, 5).value
contosbagliate = foglioExcel2.Cells(2, 6).value
foglioExcel2.Cells(2, 5).value = contogiuste + corrette
foglioExcel2.Cells(2, 6).value = contosbagliate + sbagliate
If correzionefile = 1 Then
foglioExcel2.Cells(contoriga, 3).value = "CORRETTO: "
End If
If correzionefile = 2 Then
foglioExcel2.Cells(contoriga, 3).value = "SBAGLIATO: " & CStr(UCase(correttes(random)))
End If
contoriga = contoriga + 1
cartExcel.Save()
Loop