我的问题是,即使值是 14271 和 5,'if' 中的语句也会返回 false,这是什么原因造成的?
textbox5 在 else 中返回“wybierz inna sumeFalse 5 14271”
Sub Wyplac_2()
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim sh3 As Worksheet
Set sh1 = ActiveWorkbook.Sheets("konta")
Set sh2 = ActiveWorkbook.Sheets("Interfejs")
Set sh3 = ActiveWorkbook.Sheets("stale")
y = TextBox5.Text
z = ((sh1.Range("G" & (sh3.Range("K3") + 2))) > y)
x = ((sh1.Range("G" & (sh3.Range("K3") + 2))))
If (x > y) Then
TextBox5.Text = y
sh1.Range("G" & sh3.Range("K3") + 2) = sh1.Range("G" & sh3.Range("K3") + 2) - y
TextBox4.Text = "Prosze wziasc pieniadze"
CommandButtonGrab.Visible = True
CommandButton11.Visible = False
sh3.Range("K4") = 11
GoTo gohere
Else
TextBox4.Text = "Brak srodkow na koncie"
TextBox5.Text = "Wybierz inna sume" & z & " " & y & " " & x
End If
gohere:
End Sub
答案1
Y 定义为文本,X 为数字。即使 Y 是数字,它仍被视为文本,而不是数字值。在 IF 语句之前将 Y 转换为数字值。