简体   繁体   English

Excel VBA文本到数字

[英]Excel VBA Text to Number

I am programming a little and easy add client code. 我正在编程一些简单的添加客户端代码。 But when I add a client it gives me this little error where I can't get rid off. 但是,当我添加一个客户端时,它给了我这个无法摆脱的小错误。 Maybe it will be an easy solution. 也许这将是一个简单的解决方案。 Here is my code: 这是我的代码:

Private Sub btn_Toevoegen_Click()
   Dim laatsteKlantNummer As Integer

Range("B4:B13").End(xlDown).Select
laatsteKlantNummer = ActiveCell.Value
ActiveCell.Offset(1, 0).Value = txtKlant
ActiveCell.Offset(1, 1).Value = txtNaam
ActiveCell.Offset(1, 2).Value = txtAdres
ActiveCell.Offset(1, 3).Value = txtWoonplaats
ActiveCell.Offset(1, 4).Value = txtContact
Me.Hide
Range("B4:B13").Sort Key1:=Range("B4:B13"), Order1:=xlAscending
End Sub

This code works properly but the thing happening is when it places it in the excel worksheet it is placed as text and not as number. 这段代码可以正常工作,但是发生的事情是将其放在excel工作表中时,它是作为文本而不是数字来放置的。 So it gives me the error: "Number stored as text". 因此它给我一个错误:“数字存储为文本”。 After that I can click convert to number. 之后,我可以单击转换为数字。 Like this:( http://i.imgur.com/mfMnGFI.png ) But is it possible to code it instead of clicking it all the time? 像这样:( http://i.imgur.com/mfMnGFI.png )但是可以编写代码而不是一直单击吗?

I am not sure on what line you get this error, but for example if its this one: 我不确定在哪一行会收到此错误,但是例如,如果出现以下错误:

ActiveCell.Offset(1, 4).Value = txtContact

You can add this to 'convert' it to a number: 您可以将其添加为“转换”为数字:

ActiveCell.Offset(1, 4).Value = txtContact + 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM