gpt4 book ai didi

vba - 是否可以让输入框需要 5 位数字?

转载 作者:行者123 更新时间:2023-12-04 21:22:34 25 4
gpt4 key购买 nike

我目前正在设计一个需要用户输入 3 个输入的宏,我想知道我是否可以以某种方式要求数字输入需要一个 5 位序列号。并限制任何大于或小于五位数的内容。到目前为止,这是我的代码:

Sub MRN_numbers()

Dim s, e As Integer
Dim m As String

s = InputBox("Please enter the starting 5 digit MRN number")
m = InputBox("please enter the material type")
If Not m = "ebara" Or m = "mirra" Or m = "300mm" Then
MsgBox ("Please enter valid material name!")
m = InputBox("Please enter the material type")
End If

e = InputBox("pleae enter the ending 5 digit MRN number")

Range("D1").Activate
Range("D65536").End(xlUp).Offset(1, 0).Activate

For i = s To e
If m = "ebara" Or m = "mirra" Or m = "300mm" Then

If m = "ebara" Then
For l = 1 To 5
ActiveCell.Value = i & "-" & l
ActiveCell.Offset(1, 0).Activate
ActiveCell.Offset(-1, -1).Value = "Ebara"
Next l

End If

If m = "mirra" Then
For r = 1 To 6

ActiveCell.Value = i & "-" & r
ActiveCell.Offset(1, 0).Activate
ActiveCell.Offset(-1, -1).Value = "Mirra"
Next r
End If

If m = "300mm" Then
For y = 1 To 4
ActiveCell.Value = i & "-" & y
ActiveCell.Offset(1, 0).Activate
ActiveCell.Offset(-1, -1).Value = "300mm"
Next y
End If


End If


Range("D65536").End(xlUp).Offset(1, 0).Activate






Next i

End Sub

我不知道从哪里开始,我看了视频,但没有找到任何帮助,我将继续寻找并尝试不同的方式,但对此的任何帮助将不胜感激。

最佳答案

将每个条目包装在一个 Do 循环中:

Do
s = InputBox("Please enter the starting 5 digit MRN number")
If Not (IsNumeric(s) And Len(s) = 5) Then MsgBox s & " is not a 5 digit number"
Loop Until IsNumeric(s) And Len(s) = 5

所以对于 e
Do
e = InputBox("Please enter the ending 5 digit MRN number")
If Not (IsNumeric(e) And Len(e) = 5) Then MsgBox e & " is not a 5 digit number"
Loop Until IsNumeric(e) And Len(e) = 5

关于vba - 是否可以让输入框需要 5 位数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40269440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com