Excel VBA Userform TextBox content conversion to double returns Type Mismatch error - Stack Overflow

I develop a small script for my work in Excel 365's VBA. The basic idea is a Userform where the us

I develop a small script for my work in Excel 365's VBA. The basic idea is a Userform where the users can select the desired excel export file from their work and import it to a database. To make things editable I included many TextBoxes where the data is imported from the selected workbook and may be edited before writing it to the database excel workbook.

Everything worked fine until today but now I get "Run-time error '13': Type mismatch" when trying to run my userform. The problem emerges when trying to convert the string/variant type input from the textboxes to double with the CDbl() function.

The input of the textboxes are numbers with periods as decimal separators as shown on the first picture.first pic: the input in the textbox When examining them with Watches, they show up as expected and as they did always (second picture).second pic: the variables as watches

The Debug button takes me to this line of code:

Private Sub Btn_finish_Click()
    
    Dim i%, row%
    Dim teszt As Double
    
    row = Me.Controls("Box_insert_place").Value
    
    If Me.Controls("CheckBox_check").Value = True Then
        'std measurement data'
        If Me.Controls("Box_std_OD_8").Value <> "" Then Cells(row, 16).Value = CDbl(Me.Controls("Box_std_OD_8").Value)
        If Me.Controls("Box_std_OD_1").Value <> "" Then Cells(row, 17).Value = CDbl(Me.Controls("Box_std_OD_1").Value)

    (many more lines here)

    End If

The Error occurs on this part: third picthird pic: the error occurence

This part checks whether the boxes are empty or not to avoid trying to write the contents of an empty box into the database. As the database is used to make trend calculations the datatype must be adjusted, thus I apply CDbl() on it. It worked fine until today: this is a test file I am trying to read and this was the exact same test file I used in all the tests I conducted previously where the whole code worked.

I tried writing the contents of the textbox to a variable while converting to Double like this:

test = CDbl(Me.Controls("Box_std_OD_8").Value)

Got the same error today even though yesterday this method also worked fine.

Tried saving the project, closing it and reopening. Sadly didn't help.

Tried restarting the PC, no result.

In the meantime no updates were performed to the PC or Excel I know of.


Solution: See Rory's comment for primary cause of the problem.

Also check out this thread for further information: Changing decimal separator in VBA (not only in Excel)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745266784a4619505.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信