PDA

View Full Version : [SOLVED] Reducing the code if possible



oleneazer
09-23-2004, 01:23 AM
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

Jacob Hilderbrand
09-23-2004, 01:36 AM
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")

oleneazer
09-23-2004, 02:14 AM
It was so simple.

Thanks

Jacob Hilderbrand
09-23-2004, 02:41 AM
You're Welcome

Take Care