Auto Function of Command Button

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,213
Office Version
  1. 2016
Platform
  1. Windows
Hello To All,

I am using a command button with below code:

Private Sub CommandButton2_Click()
Sheet3.Range("d1") = Range("d1") + 1
End Sub

Now each time i press the button, 1 is added in cell d1 ....

Is there anyway that i can just press the button once and 1 starts adding in Cell D1 and does not stops unless and until i press it again.... or click it again i should say ......

PLS ITS URGENT

BEST REGARDS,

HUMAYUN
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,068
Something like this might work.

You could use a boolean flag and the OnTime method.
 
Last edited:

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,213
Office Version
  1. 2016
Platform
  1. Windows
Dear Mikerickson

Thanks for your help .... but its not working

As i press the command button .... following msgbox appears which says

The macro "d:/visual basic.xls"!Incriment Cell' cannot be found

(my file name is visual basic saved in drive D:)

Pls help me out ...... its very urgent

I dont know how to deal with macro

HELP ME

AWAITING REPLY

HUMAYUN
 

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,213
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

Dear Mikerickson,

I Do not know much about the modules - but i guess yes its a normal module ..........

Good to hear from you - now it seems like with your help - i will be able to overcome the problem

Awaiting Reply

Best Regards,

HUMAYUN
 

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,213
Office Version
  1. 2016
Platform
  1. Windows
Dear Mikerickson,

I will explain it from the beginning.

I created a normal file in excel and named it Visual Basic

I am working on Sheet 1

I have the following values

A1=5
A2=5
A3=a1*a5=25

Now what i did is, i went to the the View option and then the toolbars
option and click on the control toolbox
Then i created a command button from the control toolbox on sheet 1

Then i entered the following code....

Private Sub CommandButton1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Sheet1.Range("a1") = Range("a1") + 1
End Sub

What i wanted was - when i press the command button 1 should be added in cell A1 and its happening .....

I havent done anything else .... this is regarding your question of modules - i mean to say that i havent applied anything else... i am saying this coz i dont know anything about the modules.... i guess you might have figured out that i am working on which module...

Now,,,, What i want is when i press the command button , then 1 should be added in cell A1 not stop unless and until i repress the command button again... in this way i will not have to press the command button again and again to add 1 in Cell A1....

Further more, do also let me know that is there anything like when i minimize the excel window to work on other windows then the adding 1 should not stop - unless and until i again maximize the excel window and repress the command button to stop adding 1 in Cell A1

I hope you would have understood.

Best Regards,

HUMAYUN
 

Forum statistics

Threads
1,141,001
Messages
5,703,656
Members
421,309
Latest member
ray crad

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top