0

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
6
  • Try Call Module1.Check(i) Commented Jul 6, 2016 at 20:23
  • When you call Call Check(i) in Sub UserForm_Initialize() where does i come from? Is there more code than you've posted? Commented Jul 6, 2016 at 20:26
  • I have tried that previously then there is another error "Method or data member not found" Commented Jul 6, 2016 at 20:27
  • yeah i is just a public variable which set to equal to 24 Commented Jul 6, 2016 at 20:28
  • Drop the Call and just have Module1.Check i - you won't need the parenthesis anyway Commented Jul 6, 2016 at 20:37

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Short, nice and clean

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.