Fiducioso in una vostra risposta ho scritto con l'aiuto di google questo codice

codice:
Private Sub Comando0_Click()

Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet
Dim xlWorkbook As Excel.Workbook
Dim acQuery As QueryDef
Dim objRST As Recordset
Dim strQueryName As String
strQueryName = "nominativi"
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkbook = xlApp.Workbooks.Add
Set objRST = Application.CurrentDb.OpenRecordset(strQueryName)
    
Set xlSheet = xlWorkbook.Sheets(1)

      xlSheet.Cells(1, 1).Value = "Risultati finali"
      xlSheet.Cells(1, 1).Font.Color = RGB(255, 0, 0)

      xlSheet.Range("A1:D1").Merge
      'Selection.Columns.AutoFit

    For lvlColumn = 0 To objRST.Fields.Count - 1
      xlSheet.Cells(2, lvlColumn + 1).Value = _
      objRST.Fields(lvlColumn).Name
    Next
    'Change the font to bold for the header row
    xlSheet.Range(xlSheet.Cells(1, 1), _
    xlSheet.Cells(2, objRST.Fields.Count)).Font.Bold = True
    
    xlSheet.Range(xlSheet.Cells(1, 1), _
    xlSheet.Cells(2, objRST.Fields.Count)).Font.Size = 10
    
    xlSheet.Range(xlSheet.Cells(1, 1), _
    xlSheet.Cells(2, objRST.Fields.Count)).HorizontalAlignment = xlCenter
        
     
    'Add a border to header row cells
    With xlSheet.Range(xlSheet.Cells(1, 1), _
    xlSheet.Cells(2, objRST.Fields.Count)).Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With xlSheet.Range(xlSheet.Cells(1, 1), _
    xlSheet.Cells(2, objRST.Fields.Count)).Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With xlSheet.Range(xlSheet.Cells(1, 1), _
    xlSheet.Cells(2, objRST.Fields.Count)).Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With xlSheet.Range(xlSheet.Cells(1, 1), _
    xlSheet.Cells(2, objRST.Fields.Count)).Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

With xlSheet
    .Range("A3").CopyFromRecordset objRST
    .Name = Left(strQueryName, 31)
End With

xlSheet.Cells(18, 1).Value = "lavorativi"
xlSheet.Cells(19, 1).Value = "formativi"
xlSheet.Cells(20, 1).Value = "avvio impresa"
xlSheet.Cells(21, 1).Value = "altro"
xlSheet.Cells(22, 1).Value = "Totale"


lavorativi = xlApp.CountIf(Range("d3:d15"), "lavorativo")
xlSheet.Cells(18, 4).Value = lavorativi

formativi = xlApp.CountIf(Range("d3:d15"), "formativo")
xlSheet.Cells(19, 4).Value = formativi

avvioImpresa = xlApp.CountIf(Range("d3:d15"), "avvio impresa")
xlSheet.Cells(20, 4).Value = avvioImpresa

altro = xlApp.CountIf(Range("d3:d15"), "altro")
xlSheet.Cells(21, 4).Value = altro

totale = lavorativi + formativi + avvioImpresa + altro
xlSheet.Cells(22, 4).Value = totale


Set xlSheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing

End Sub
Ho da porvi alcune domande:
1) Come faccio ad adattare automaticamente la larghezza delle colonne. Cercando su internet ho letto di selection.columns.autofit ma non sono riuscito ad integrarlo nel mio codice.
2) Perchè la funzione conta se mi restituisce i risultati corretti esattamente una volta su due (nel senso che premo il pulsante e funziona, lo ripremo e non mi viene visualizzato nessun valore numerico e in compenso mi appare una finestra di errore di runtime '1004' Metodo Range dell'oggetto '_Global' non riuscito, lo ripremo e funziona e così via.
3) Terza e ultima domanda. In questa mia prova ho specificato le celle in cui visualizzare i risultati (le righe da 18 a 22) ma ovviamente non so a priori il numero di record restituito dalla query e quindi dovrei accodare tali conteggi alla fine. Come faccio?

Grazie per l'attenzione.