Consulting

Results 1 to 4 of 4

Thread: Reducing the code if possible

  1. #1

    Reducing the code if possible

    Here's my little problem

    I have a workbook with a "personalizede toolbar
    On this toolbar, I've got n buttons (n=A to I)
    With theses buttons I've got theses macros

    Public Sub prms() 
    Dim ce As Range, rg As Range
    End Sud
     
    Sub VCellA()
    prms
    Set rg=Application.Selection
    For Each ce In rg
    ce.Value="A"
    Next ce
    End Sub
    I've copy VcellA() code for each letters (A to I)
    So I've got the "module"
    Sub VCellA(), Sub VCellB() ... Sub VCellI()

    Is there a way to have only one macro who indentify wich button I click on
    and adjust the right letter value in the selected cells?

    Thank for your help

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You could just put

    rg.value = "A"
    and skip the loop.

    Also you can set an argument for the sub and just call it different for each button.

    Sub VCell(MyText As String)
    Then for each button call the macro like this:

    Call VCell("A") 
    Call VCell("B")

  3. #3
    It was so simple.

    Thanks

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

Posting Permissions

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