在用户窗体Excel中调用公共子程序VBA

问题描述:

我最近开始学习excel vba,此刻我坚持从用户窗体Excel VBA中调用公用子程序。我一直在试图把子程序放到一个模块和其他几个地方,但它仍然给我一个错误。(Sub或Function not defined!)在用户窗体Excel中调用公共子程序VBA

请问您可否请正确的方向引导。

函数本身在模块1

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 

在这里,我在一个窗体

Private Sub UserForm_Initialize() 
     Call Check(i) 
    End Sub 
+0

尝试'呼叫Module1.Check(我)' – Dave

+0

当你调用子UserForm_Initialize呼叫检查(I)()哪里我从哪里来?是否有更多的代码比你发布的? – Absinthe

+0

我曾尝试过,然后有另一个错误“方法或数据成员找不到” – John

不要将其作为回答你目前的问题调用它。只是一个建议:

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 
+0

短,很好,干净 –