我允许用户将数据输入到Excel工作表。我希望他们输入的数据是完整的普通数字。如果用户用逗号输入excel,则会忽略逗号并且只有行数据的整数。有没有办法做到这一点?我想有办法改变行的数据类型吗?
答案 0 :(得分:1)
答案 1 :(得分:1)
这不会完全符合您的要求,因为它不会允许他们首先输入逗号,而不是删除逗号。
答案 2 :(得分:1)
ThisWorkbook
上粘贴此代码:Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey ","
End Sub
Private Sub Workbook_Open()
Application.OnKey ",", "NotAllowed"
End Sub
Module
粘贴此内容:Public Sub NotAllowed()
MsgBox ("Not allowed to use the "","" key!")
End Sub
现在,只要有人,,他们就会看到:
答案 3 :(得分:0)
此宏将主动从指定范围内的任何输入数据中删除数据和格式的逗号。您需要右键单击工作表名称并选择“查看代码”以添加事件。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NO_COMMAS_REGION As Range
Set NO_COMMAS_REGION = Range("A:A") ' Replace this with whatever the region is where you want to prevent commas
For Each cell In Target
If Not (Application.Intersect(cell, NO_COMMAS_REGION) Is Nothing) Then
If InStr(cell.Value, ",") > 0 Then
cell.Value = Replace(cell.Value, ",", "")
End If
cell.NumberFormat = "0"
End If
Next cell
End Sub