vba code doesn't run through all the way? It takes 2 clicks of a command button to execute??

Xceller

Active Member
Joined
Aug 24, 2009
Messages
265
vba Gurus:

Thanks in advance for your help. I attached the code below to a command button, but it takes 2 clicks to execute the code. Any ideas?? Could this be accomplished in a single click of the button.

Sub CnvtTextDate1()

Dim rng As Variant
For Each rng In Selection
rng.Value = Trim(rng)
rng.NumberFormat = "mm/dd/yy;@"
Next rng

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You need to change the name of your sub to the name of the command button
Something like Sub CommandButton1Click()
 
Upvote 0
You need to change the name of your sub to the name of the command button
Something like Sub CommandButton1Click()

Hi Michael - Thanks for your reply. It is a Form button not a command button. I right click the Form button and attached the code to the button.
 
Upvote 0
I attached the code below to a command button

You did say a Command button
OK, Right click on the form button and select view code.
Now paste the code you have in between the start and end sub lines
 
Upvote 0
You did say a Command button
OK, Right click on the form button and select view code.
Now paste the code you have in between the start and end sub lines

I did that, but it takes 2 clicks of the button to execute the code completely.
 
Upvote 0
Xceller

What do you mean exactly by it doesn't execute the code completely?

Does it not execute at all the first time you click the button?

Or when you click the button the first time the code is executed but doesn't run the code on the entire range you've selected?
 
Upvote 0

Forum statistics

Threads
1,215,016
Messages
6,122,700
Members
449,092
Latest member
snoom82

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
Back
Top