Buongiorno a tutti e grazie in anticipo,
devo inserire su un foglio è excel una serie di informazioni derivanti da diverse combobox e texbox, va tutto bene però non mi trasforma il nome del mese visualizzato sulla combobox in numero che dovrà essere inserito sul file excel. Vi faccio un esempio:
se sulla combobox Cbo_Mese è visualizzato il mese di luglio sul file excel alla colonna F dovrà esserci scritto 7
Grazie
Private Sub Cmb_inserisci_Click()
Dim ur As Integer
Dim startDate As Date
Dim endDate As Date
Dim currentDate As Date
Dim ws As Worksheet
Dim selectedMonth As String
Dim monthNumber As Integer
Dim lastRow As Long
Dim nextRow As Long
Dim i As Integer
Dim dayStart As Integer, dayEnd As Integer
Foglio8.Activate
Set ws = ThisWorkbook.Sheets("Calendario_visita")
dayStart = CInt(Cbo_giorno_da.Value)
dayEnd = CInt(Cbo_giorno_a.Value)
startDate = DateSerial(CInt(Cbo_Anno.Value), MonthNumberFromName(Cbo_Mese.Value), dayStart)
endDate = DateSerial(CInt(Cbo_Anno.Value), MonthNumberFromName(Cbo_Mese2.Value), dayEnd)
nextRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
currentDate = startDate
Do While currentDate <= endDate
ws.Cells(nextRow, 1).Value = Cbo\_Clienti.Value
ws.Cells(nextRow, 2).Value = Txtagente.Value
ws.Cells(nextRow, 3).Value = Txtpromoter.Value
ws.Cells(nextRow, 4).Value = Txtarea\_manager.Value
ws.Cells(nextRow, 5).Value = Cbo\_Anno.Value
ws.Cells(nextRow, 6).Value = monthName(Month(currentDate))
ws.Cells(nextRow, 7).Value = Day(currentDate)
ws.Cells(nextRow, 8).Value = Txtcodice\_cliente.Value
ws.Cells(nextRow, 9).Value = Txtnota.Value
currentDate = currentDate + 1
nextRow = nextRow + 1
Loop
MsgBox "Dati inseriti con successo!"
End sub
Function MonthNumberFromName(monthName As String) As Integer
Dim monthNames As Variant
monthNames = Array("gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", \_
"luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre")
Dim i As Integer
For i = LBound(monthNames) To UBound(monthNames)
If StrComp(monthNames(i), monthName, vbTextCompare) = 0 Then
MonthNumberFromName = i + 1
Exit Function
End If
Next i
MonthNumberFromName = 0
End Function