VBA two buttons calling one Sub

I have two statistics tables in one Excel file. Their names are OO and XX.

I have separate subroutines to export and import each of OO and XX. That is:

1.Sub OO-export()
'do output data from OO sheet
End Sub

2.Sub XX-export()
'do output data from XX sheet
End Sub

3.Sub OO-import()
'Import Data to OO sheet
End Sub

4.Sub XX-import()
'Import Data to XX sheet
End Sub

Both import subroutines contain very similar code, and both export subroutines contain very similar code.

I would like to refactor the OO-/XX-specific subroutines to more generic import and export subroutines e.g. TT-import and TT-export.

The generic subroutines would conditionally process either OO or XX depending on which button the user clicks e.g. OO-button or XX-button.

How can I create common subroutines that can process the right table depending on which button was clicked? Give me some hints

1 answer

  • answered 2021-03-09 04:31 MimiTsai

    I'm sorry for the unclear description.

    My fault and thanks for responding.

    I have two Statistics table in one Excel. Their names are OO and XX

    Example of my code:

    1.Sub OO-export()
    'do output data from OO sheet
    End Sub
    
    2.Sub XX-export()
    'do output data from XX sheet
    End Sub
    
    3.Sub OO-import()
    'Import Data to OO sheet
    End Sub
    
    4.Sub XX-import()
    'Import Data to XX sheet
    End Sub
    

    The above code needs to be modified twice.

    So... I want to change method, for the export data part.

    My idea is to create code:

    Sub TT-export()
    'do output data action
    End sub
    

    Then use the button to decide which data to export. When I press the OO button, the OO data is exported.

    I try to use Sub call Function,but I don’t know how to set the value

    Is the supplementary explanation clear?

    My english is bad...