Ragazzi salve a tutti,![]()
ho un baco da risolvere in questo codice:
in userform:
in un modulo:codice:Private Sub CommandButton1_Click() 'INSERISCI MESE Dim M As Integer Dim A As Integer Dim J As Integer Dim Giorni As Integer Dim chegiorno As String Dim firstrow As Integer Dim firstcol As Integer Dim R As Integer Dim C As Integer If ComboBox1.Text = "" Then MsgBox "Nessun MESE selezionato." & Chr(13) & "Seleziona il MESE dall'elenco a discesa." ElseIf ComboBox2.Text = "" Then MsgBox "Nessun ANNO selezionato." & Chr(13) & "Seleziona l'ANNO dall'elenco a discesa." Else: Dim DataIn As Object A = ComboBox2.Value ' prendi l'anno M = PrendiMese(ComboBox1.Value) ' prendi il mese Set zona = Range(Range("A1"), Range("A1").End(xlDown)).Rows DataBox = CDate(CStr(M) & "/" & CStr(A)) firstrow = 1 firstcol = 1 R = firstrow C = firstcol For Each DataIn In zona If DataIn = DataBox Then MsgBox "Già cè" Exit Sub Else: MsgBox "Non cè" Giorni = UltimoDelMese(M, LeapYear(A)) For J = 1 To Giorni chegiorno = CDate(CStr(J) & "/" & CStr(M) & "/" & CStr(A)) Cells(R, C) = chegiorno Cells(R, C + 1) = "gigi" Cells(R, C + 2) = "pino" Cells(R, C + 3) = "ninos" R = R + 1 Next MsgBox "Completato!" Exit Sub End If Next End Sub
Problema: durante il ciclo dell'userform(segnato in rosso), inizia col segnarmi mese/giorno/anno sul foglio excell, poi dal giorno 13 mi segna giorno/mese/anno. Non trovo dove sbaglio. Vorrei la solita dicitura giorno/mese/anno.codice:Function UltimoDelMese(Mese As Integer, Bisest As Boolean) As Integer Select Case Mese Case 1, 3, 5, 7, 8, 10, 12 UltimoDelMese = 31 Case 4, 6, 9, 11 UltimoDelMese = 30 Case 2 If Bisest Then UltimoDelMese = 29 Else UltimoDelMese = 28 End If End Select End Function Function LeapYear(YYYY As Integer) As Integer LeapYear = YYYY Mod 4 = 0 And (YYYY Mod 100 <> 0 Or YYYY Mod 400 = 0) End Function Function PrendiMese(strItem As String) As Integer Select Case LCase(strItem) Case "gennaio" PrendiMese = 1 Case "febbraio" PrendiMese = 2 Case "marzo" PrendiMese = 3 Case "aprile" PrendiMese = 4 Case "maggio" PrendiMese = 5 Case "giugno" PrendiMese = 6 Case "luglio" PrendiMese = 7 Case "agosto" PrendiMese = 8 Case "settembre" PrendiMese = 9 Case "ottobre" PrendiMese = 10 Case "novembre" PrendiMese = 11 Case "dicembre" PrendiMese = 12 Case Else PrendiMese = 0 End Select End Function
Grazie a tutti
![]()

Rispondi quotando
il tutto funge, eliminando anche le due funzioni UltimodelMese e LapYear, ma l'errore rimane. Difatti facendo partire la sub inserisce la data in formato mese/giorno/anno fino al giorno 13 poi ritorna nel formato che voglio giorno/mese/anno :master:.
