UserForm not converting to number

goncalogera

New Member
Joined
Nov 10, 2020
Messages
14
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
  3. 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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
The values in the textboxes are text, if you want them to be treated as numeric you need to convert them.

If you want a specific data type use one of the conversion functions like CLng, CDbl etc., for a more general approach us Val
VBA Code:
sh.Range("P" & n + 1).Value = Val(Me.ComissaoBox.Value)
 
Upvote 0
Solution
The values in the textboxes are text, if you want them to be treated as numeric you need to convert them.

If you want a specific data type use one of the conversion functions like CLng, CDbl etc., for a more general approach us Val
VBA Code:
sh.Range("P" & n + 1).Value = Val(Me.ComissaoBox.Value)
Its always such a simple answer and I fail to see it... It as you say, worked perfectly! Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,887
Messages
6,122,095
Members
449,064
Latest member
Danger_SF

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top