Insert a function through a command button

S

Subodh

I have custom function created in VBA.
I want to use the button to insert the function.
I tried to accomplish is something like inserting the Sum function by
clicking the button so that =sum() appears in the cell and i can type
the number/parameters required.
But, when i tried to do that using a macro recorder then it cannot be
done
Any help would be appreciated.
Thanks in advance.
 
B

Bob Phillips

I did something similar to this. The problem is that you can't have your
code inserting and the user interacting as Excel does natively, so what I
did was to throw up a dialog asking the user to select the cell to be
included, using Application.Inputbox(...Type:=8) and then get that cell
address and inject it into my string, and return the string from the
function.
 
S

Subodh

I did something similar to this. The problem is that you can't have your
code inserting and the user interacting as Excel does natively, so what I
did was to throw up a dialog asking the user to select the cell to be
included, using Application.Inputbox(...Type:=8) and then get that cell
address and inject it into my string, and return the string from the
function.

--

HTH

Bob






- Show quoted text -

I think in my case, application.inputbox is not needed.
Coz, the desired cell is already selected So, its very easy to get
that cell address.
So, I only need to get a way to inject the cell address to the string
to use the function, i hope
that it would be possible.
Thanks for your prompt response.
 
B

Bob Phillips

If the parameter cell is selected, what is the target cell (for the
formula)?

And can you be sure some other cell won't get selected?

--

HTH

Bob

I did something similar to this. The problem is that you can't have your
code inserting and the user interacting as Excel does natively, so what I
did was to throw up a dialog asking the user to select the cell to be
included, using Application.Inputbox(...Type:=8) and then get that cell
address and inject it into my string, and return the string from the
function.

--

HTH

Bob






- Show quoted text -

I think in my case, application.inputbox is not needed.
Coz, the desired cell is already selected So, its very easy to get
that cell address.
So, I only need to get a way to inject the cell address to the string
to use the function, i hope
that it would be possible.
Thanks for your prompt response.
 
S

Subodh

If the parameter cell is selected, what is the target cell (for the
formula)?

And can you be sure some other cell won't get selected?

--

HTH

Bob





I think in my case, application.inputbox is not needed.
Coz, the desired cell is already selected So, its very easy to get
that cell address.
So, I only need to get a way to inject the cell address to the string
to use the function, i hope
that it would be possible.
Thanks for your prompt response.- Hide quoted text -

- Show quoted text -

I want to insert the function in the cell that is selected.
So, in my opinion the selected cell itself is the target cell
Or, let me explain again what i need to do.
I have to insert my custom function lets say mysub() in the selected
cell A1
Now, I have selected the cell A1
My funciton has one argument (and the agrument is not optional)
So, when i click on the button, and then run the macro,
I should be able to get in the selected cell something like
="=mysub(..)"
with the cursor in between the parenthesis. Like the one we get when
we click the appropriate buttom for the sum function as an example.
Thanks for your concern.
 
S

Subodh

I want to insert the function in the cell that is selected.
So, in my opinion the selected cell itself is the target cell
Or, let me explain again what i need to do.
I have to insert my custom function lets say mysub() in the selected
cell A1
Now, I have selected the cell A1
My funciton has one argument (and the agrument is not optional)
So, when i click on the button, and then run the macro,
I should be able to get in the selected cell something like
="=mysub(..)"
with the cursor in between the parenthesis. Like the one we get when
we click the appropriate buttom for the sum function as an example.
Thanks for your concern.- Hide quoted text -

- Show quoted text -

I didn't thought it was a difficult problem,
but i don't know if it was because i couldn't explain the case or my
question properly or
that it was really a difficult problem??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top