Beneindias
Board Regular
- Joined
- Jun 21, 2022
- Messages
- 120
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi to all of you,
I have an excel sheet with an Inputbox, where i'm asker to put the number of the month, the year and a third value.
Problem is, it was working as intended during 2023, but now, it's swaping the month for the day.
I'm in Europe, we use dd/mm/yyyy and I'm trying to make the file for February 2024 (month 2).
But, as I do this, the date in cell D1 is always transformed as "02/01/2024" when I want "01/02/2024".
If I go to cell D1 and manualy enter "01/02/2024" it stays how it should.
I don't think that the problem is in the macro code, but I can't find a solution to this.
Cell is formated as Date dd/mm/yyyy.
My code is this one:
Thank you all in advance
I have an excel sheet with an Inputbox, where i'm asker to put the number of the month, the year and a third value.
Problem is, it was working as intended during 2023, but now, it's swaping the month for the day.
I'm in Europe, we use dd/mm/yyyy and I'm trying to make the file for February 2024 (month 2).
But, as I do this, the date in cell D1 is always transformed as "02/01/2024" when I want "01/02/2024".
If I go to cell D1 and manualy enter "01/02/2024" it stays how it should.
I don't think that the problem is in the macro code, but I can't find a solution to this.
Cell is formated as Date dd/mm/yyyy.
My code is this one:
VBA Code:
Public Sub MyInputBox()
Dim MyInputMonth As String
Dim MyInputYear As String
Dim MyInputPago As String
Dim NumericInputMonth As Boolean
Dim NumericInputYear As Boolean
Dim NumericInputPago As Boolean
Dim MyInputDate As String
'Box to user input
'Month number
MyInputMonth = InputBox("Escrever número do novo mês", "Iniciar novo mês", "Número do novo mês")
NumericInputMonth = IsNumeric(MyInputMonth)
'Year number
MyInputYear = InputBox("Escrever número do ano", "Iniciar novo mês", "Número do ano")
NumericInputYear = IsNumeric(MyInputYear)
'Value
MyInputPago = InputBox("Adicionar valor pago", "Valor pago", "Valor pago!")
NumericInputPago = IsNumeric(MyInputPago)
'Checks if month number is between 1 and 12
If NumericInputMonth Then
If MyInputMonth >= 1 And MyInputMonth <= 12 Then
MyInputDate = 1 & "-" & MyInputMonth & "-" & MyInputYear
'Calls macro to delete table cells
Call Clearcells
'Adds date to cell D1
Range("D1").Value = MyInputDate
Range("G53").Value = MyInputPago
Else
'GoTo errHand
MsgBox "Número de mês mal introduzido"
End If
Else
'GoTo errHand
MsgBox "Tem que introduzir número do mês"
End If
Exit Sub
'errHand:
'MsgBox "Número de mês mal introduzido"
End Sub
Thank you all in advance