0
votes

I recently started to learn excel vba and at the moment I am stuck calling Public Subroutine from a userform Excel VBA. I have been trying to put the subroutine into a module and few other places but still it gives me an error.(Sub or Function not defined!)

Can you please guide in the right direction.

The function itself in 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

Here I am calling it in a userform

    Private Sub UserForm_Initialize()
        Call Check(i)
    End Sub
1
Try Call Module1.Check(i)Dave
When you call Call Check(i) in Sub UserForm_Initialize() where does i come from? Is there more code than you've posted?Absinthe
I have tried that previously then there is another error "Method or data member not found"John
yeah i is just a public variable which set to equal to 24John
Drop the Call and just have Module1.Check i - you won't need the parenthesis anywayDave

1 Answers

2
votes

Not intended as an answer to your current problem. Just a suggestion:

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