基于Userform上的用户输入在Excel表格中输入数字 [英] Input Number to Excel Sheet Based on User Input on Userform

查看:136
本文介绍了基于Userform上的用户输入在Excel表格中输入数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户窗体,其中用户将信息输入到文本框中,然后点击命令按钮,该按钮将各种文本框中的信息发送到Excel工作表中的不同列。 代码工作正常,但文本框除外,其中
用户将输入一个数字。 对于那个方框,文本框将数字作为文本发送到工作表,而不是数字。

I have a userform where the user inputs information into textboxes, and then hits a command button, which sends the information from the various textboxes to different columns in an Excel sheet.  The code works fine, except for a textbox where the user will input a number.  for that box, the textbox sends the number to the sheet as text, not as a number.

我已经尝试了各种方法来解决这个问题,并将我的"解决方案"放在了在代码中的不同位置,但到目前为止没有任何工作。 我应该使用文本框以外的东西吗? 有没有办法让文本作为数字发送? 在
之后,userform将该号码作为文本发送给Excel,Excel立即识别出问题,并发出一个感叹号,并注明一个号码已作为文本输入,并提供了隐藏它的选项,但当然我首先要输入数字
作为数字。 如果有人有任何想法,我会很感激。 谢谢!

I have tried various ways to fix this, and have put my "solutions" in different places in the code, but nothing has worked so far.  Should I be using something besides a textbox?  Is there a way to have the text be sent as a number?  After the userform sends the number to Excel as text, Excel immediately recognizes the problem and puts up a little exclamation point with a notice that a number has been entered as text and gives the option to covert it, but of course I'd rather have the number entered as a number in the first place.  If anyone has any ideas, I'd appreciate it.  Thanks!

我正在运行Vista(Excel 2007)。

I am running Vista (Excel 2007).

推荐答案

如果是IsNumeric(Me.TextBox1。价值)然后

 范围("Whatever")。值= Val(Me.TextBox1.Value)

否则为
  MsgBox Me.TextBox1.Value& "不是有效数字"

结束如果
If IsNumeric(Me.TextBox1.Value) Then
  Range("Whatever").Value = Val(Me.TextBox1.Value)
Else
  MsgBox Me.TextBox1.Value & " is not a valid number"
End If


这篇关于基于Userform上的用户输入在Excel表格中输入数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆