Consulting

Results 1 to 16 of 16

Thread: calling sub from module not work

  1. #1
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location

    calling sub from module not work

    I had a code which will run from command button click but i need to run it twice on different 2 sheets so i write the code in command area then i write for the other sheet in module then call it on my command area but it's not work correct?

    Could anybody tell me why it's not work?

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Suny,

    Could you attach a sample workbook? It is hard to understand your question and I think that this would help.

    Mark

  3. #3
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location
    Quote Originally Posted by GTO
    Hi Suny,

    Could you attach a sample workbook? It is hard to understand your question and I think that this would help.

    Mark
    thanks for your reply
    here is sample workbook
    the code work well but the code on module don't work well inspite of they are the same except the sheets number
    Attached Files Attached Files

  4. #4
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location
    Quote Originally Posted by suny100
    thanks for your reply
    here is sample workbook
    the code work well but the code on module don't work well inspite of they are the same except the sheets number

    hi GTO didn't you find what's happening here ?

  5. #5
    VBAX Tutor Benzadeus's Avatar
    Joined
    Dec 2008
    Location
    Belo Horizonte, Brazil
    Posts
    271
    Location
    I get an error from this line:
    Module4.waste
    Delete it.
    ---
    Felipe Costa Gualberto
    Microsoft Excel MVP
    http://www.ambienteoffice.com.br

  6. #6
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location
    Quote Originally Posted by Benzadeus
    I get an error from this line:
    Module4.waste
    Delete it.
    what iam trying to do is call the sub waste from module 4 "which contain same code except sheet number is differs than this code" so i can run it on 2 sheets

  7. #7
    VBAX Tutor Benzadeus's Avatar
    Joined
    Dec 2008
    Location
    Belo Horizonte, Brazil
    Posts
    271
    Location
    So, send the entire workbook to us, because the one you sent there is no modules.
    ---
    Felipe Costa Gualberto
    Microsoft Excel MVP
    http://www.ambienteoffice.com.br

  8. #8
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location
    Quote Originally Posted by Benzadeus
    So, send the entire workbook to us, because the one you sent there is no modules.

    i'm sorry
    this is the sample workbook contain the module
    Attached Files Attached Files

  9. #9
    VBAX Mentor
    Joined
    Aug 2008
    Posts
    323
    Location
    If I understand it right this should fix it
    You are calling the sub routine in a wrong way

    Replace the line
    Module1.waste
    in the button click event with

    call waste()

    Thank should fix it.
    I am a Newbie, soon to be a Guru

  10. #10
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location
    Quote Originally Posted by nepotist
    If I understand it right this should fix it
    You are calling the sub routine in a wrong way

    Replace the line
    Module1.waste
    in the button click event with

    call waste()

    Thank should fix it.
    Of course it run the sub but it find only the first number on waste sheet , not check the other numbers but it's work well with finished

  11. #11
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location
    Quote Originally Posted by suny100
    Of course it run the sub but it find only the first number on waste sheet , not check the other numbers but it's work well with finished

    Is there any idea ????

  12. #12
    VBAX Mentor
    Joined
    Aug 2008
    Posts
    323
    Location
    Could explain what is it that you are actually trying to accomplish. I am a bit lost :|
    I am a Newbie, soon to be a Guru

  13. #13
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location
    Quote Originally Posted by nepotist
    Could explain what is it that you are actually trying to accomplish. I am a bit lost :|
    as you see in the workbook , i have 3 sheets :
    1- reservation
    2-Finished
    3- waste

    I want when i click on Check button on reservation sheet , check if the skill card no. is founded in the other 2 sheets.

    that all what i try to accomplish

  14. #14
    VBAX Regular
    Joined
    May 2011
    Posts
    28
    Location
    Quote Originally Posted by suny100
    as you see in the workbook , i have 3 sheets :
    1- reservation
    2-Finished
    3- waste

    I want when i click on Check button on reservation sheet , check if the skill card no. is founded in the other 2 sheets.

    that all what i try to accomplish

    Is there any help here?

  15. #15
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    You had a sheet called waste and a sub called waste.

    The Command button also seemed to have duplcate code

    Try these

    [vba]
    Private Sub CommandButton9_Click()
    Call WasteSub
    End Sub
    [/vba]


    and

    [vba]
    Sub WasteSub()
    Dim valFIND As Range
    Dim iRow As Long
    Dim sB As String
    For iRow = 2 To 500
    If Cells(iRow, "E") = "1" And Cells(iRow, "E") <> "" Then
    If Cells(iRow, "B").Value <> "" Then
    sB = Cells(iRow, "B").Value
    End If
    On Error Resume Next
    Set valFIND = Sheet4.Cells.Find(sB, LookIn:=xlValues, LookAt:=xlPart)
    If valFIND Like "*" & sB Then
    Sheet4.Activate
    MsgBox "Value " & valFIND & " was waste"
    End If
    End If
    Next iRow
    End Sub
    [/vba]

    Other than these, I have no more ideas

    Paul

  16. #16
    VBAX Mentor
    Joined
    Aug 2008
    Posts
    323
    Location
    Quote Originally Posted by suny100
    Is there any help here?
    Please find the attachment, I have modified the code to check.
    Attached Files Attached Files
    I am a Newbie, soon to be a Guru

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •