我有一个 vba 脚本,我想比较从宏用户窗体接收的 ItemNumber。 但是由于某种原因,如果我使用 ItemNumber 变量,它不起作用。 正在传递该数字,因为如果我告诉它设置对该变量的调用,它确实设置正确。
我有这个 vba 脚本,如果我更改
If ItemNumber = myRange.Cells(r, 1).Value Then
声明是
If "991182" = myRange.Cells(r, 1).Value Then
Sub subtract(Qty, ItemNumber, OptionButton1, OptionButton2, OptionButton3, OptionButton4, OptionButton5, OptionButton6)
Dim myRange As Range
Dim r As Double, c As Long
Dim ws As Worksheet
' Change worksheet designations as needed
Set ws = ActiveWorkbook.Worksheets("On Hands")
Set myRange = ws.Range("A3:A10")
For r = 1 To myRange.Rows.Count
' For c = 1 To myRange.Columns.Count
If ItemNumber = myRange.Cells(r, 1).Value Then
If OptionButton1 = True Then
myRange.Cells(r, 3).Value = myRange.Cells(r, 3).Value - Qty
MsgBox "Removed " + Qty + " from your On Hands Sheet Item #: " + ItemNumber
End If
If OptionButton2 = True Then
myRange.Cells(r, 3).Value = myRange.Cells(r, 3).Value - Qty
MsgBox "Removed " + Qty + "from your On Hands Sheet Item #: " + ItemNumber
End If
If OptionButton3 = True Then
myRange.Cells(r, 3).Value = myRange.Cells(r, 3).Value - Qty
MsgBox "Removed " + Qty + " from your On Hands Sheet Item #: " + ItemNumber
End If
If OptionButton4 = True Then
myRange.Cells(r, 3).Value = myRange.Cells(r, 3).Value + Qty
MsgBox "Added " + Qty + " to your On Hands Sheet Item #: " + ItemNumber
End If
If OptionButton5 = True Then
myRange.Cells(r, 3).Value = myRange.Cells(r, 3).Value + Qty
MsgBox "Added " + Qty + " to your On Hands Sheet Item #: " + ItemNumber
End If
If OptionButton6 = True Then
myRange.Cells(r, 3).Value = myRange.Cells(r, 3).Value + Qty
MsgBox "Added " + Qty + " to your On Hands Sheet for Item #: " + ItemNumber
' myRange.Cells(r, 3) = myRange.Cells(r, 3).Value + Qty
End If
End If
'Next c
Next r
End Sub
也许如果你Char
进入ItemNumber
你可以执行以下操作:
If CStr(ItemNumber) = Cstr(myRange.Cells(r, 1).Value) Then
它会将ItemNumber
转换为string
,并将单元格值转换为