goncalogera
New Member
- Joined
- Nov 10, 2020
- Messages
- 14
- Office Version
- 2019
- Platform
- Windows
- Mobile
- Web
Hi, I have a userform that fills a table with the values from the boxes but sometimes the output in the table is in the form of text and not number. Ive tried many solutions but none seem to work... Bellow is the code for filling the table in case is needed. When the MontanteBox, EURBox, SpreadBox and ComissaoBox are copied to the table they go as text and not as number which affects the calculations in the destination table. Any suggestion would be appreciated! Many thanks!
VBA Code:
Private Sub SubmitButton_Click()
''''''''''''' Data Validation '''''''''''''
If VBA.IsNumeric(Me.MontanteBox.Value) = False Then
MsgBox "Por favor insira um montante válido (numérico)", vbCritical
Exit Sub
End If
If Me.FornecedorBox.Value = "" Then
MsgBox "Por favor insira um fornecedor válido", vbCritical
Exit Sub
End If
If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False Then
MsgBox "Por favor indique se o cliente aceita factoring ou não", vbCritical
Exit Sub
End If
If Me.txtStartDate.Value = False Then
MsgBox "Por favor indique a data de início do contrato", vbCritical
Exit Sub
End If
If Me.txtDueDate.Value = False Then
MsgBox "Por favor indique a data de pagamento do confirming", vbCritical
Exit Sub
End If
If Me.BancoBox.Value = "" Then
MsgBox "Por favor selecione um banco", vbCritical
Exit Sub
End If
If Me.txtPedido.Value = False Then
MsgBox "Por favor indique a data do pedido do contrato", vbCritical
Exit Sub
End If
If VBA.IsNumeric(Me.IDBox.Value) = False Then
MsgBox "Por favor insira um ID válido (numérico)", vbCritical
Exit Sub
End If
''''''' Check for duplicates ''''''''
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Confirmings")
Dim n As Long
If Application.WorksheetFunction.CountIf(sh.Range("A:A"), Me.IDBox.Value) > 0 Then
MsgBox "Este ID já está atribuído a outro confirming. Por favor confirme se a informação está duplicada", vbCritical
Exit Sub
End If
'''''''''''' Insert/ Check last used row '''''''''''''
n = sh.Range("A" & Application.Rows.Count).End(xlUp).Row
sh.Range("I" & n + 1).Value = Me.MontanteBox.Value
sh.Range("C" & n + 1).Value = Me.FornecedorBox.Value
sh.Range("E" & n + 1).Value = Me.txtStartDate.Value
sh.Range("F" & n + 1).Value = Me.txtDueDate.Value
sh.Range("B" & n + 1).Value = Me.BancoBox.Value
sh.Range("D" & n + 1).Value = Me.txtPedido.Value
sh.Range("N" & n + 1).Value = Me.EURBox.Value
sh.Range("A" & n + 1).Value = Me.IDBox.Value
sh.Range("O" & n + 1).Value = Me.SpreadBox.Value
sh.Range("P" & n + 1).Value = Me.ComissaoBox.Value
Me.MontanteBox.Value = ""
Me.FornecedorBox.Value = ""
Me.OptionButton1.Value = False
Me.OptionButton2.Value = False
Me.txtDueDate.Value = Date
Me.txtStartDate.Value = Date
Me.BancoBox.Value = ""
Me.EURBox.Value = ""
Me.txtPedido.Value = Date
Me.IDBox.Value = ThisWorkbook.Sheets("Confirmings").Range("A" & Rows.Count).End(xlUp).Value + 1
MsgBox "Foi adicionado um novo confirming", vbInformation
End Sub