我最近开始学习excel vba,目前我无法从用户表单Excel VBA调用Public Subroutine。我一直试图将子程序放入一个模块和其他几个地方,但它仍然给我一个错误。(Sub或Function未定义!)
请你指导正确的方向。
module1中的函数本身
Public Sub Check(j As Integer)
If Worksheets("VBA").Cells(j, 19).Value = "Y" Then
imgA.Visible = True
imgB.Visible = False
imgC.Visible = False
imgD.Visible = False
ElseIf Worksheets("VBA").Cells(j, 19).Value = "N" Then
imgA.Visible = False
imgB.Visible = True
imgC.Visible = False
imgD.Visible = False
ElseIf Worksheets("VBA").Cells(j, 19).Value = "X" Then
imgA.Visible = False
imgB.Visible = False
imgC.Visible = True
imgD.Visible = False
ElseIf Worksheets("VBA").Cells(j, 19).Value = "F" Then
imgA.Visible = False
imgB.Visible = False
imgC.Visible = False
imgD.Visible = True
End If
End Sub
我在这里用userform
调用它 Private Sub UserForm_Initialize()
Call Check(i)
End Sub
答案 0 :(得分:2)
不打算作为您当前问题的答案。只是一个建议:
Public Sub Check(j As Integer)
Dim v
v = Worksheets("VBA").Cells(j, 19).Value
imgA.Visible = (v = "Y")
imgB.Visible = (v = "N")
imgC.Visible = (v = "X")
imgD.Visible = (v = "F")
End Sub