VBA: Question

SteveOranjin

Board Regular
Joined
Dec 18, 2017
Messages
170
Hello There,

I'm learning a lot about VBA but I have a quick question.

If a macro can be performed more than once on a given cell, will it be performed as many times as the rules which govern it allow? Or will it only make that initial run through and then have to be run again to get the rest.

An example: If I have fifty spaces in a cell, and I set up a macro to turn all Double Spaces (that is "_""_" lines added for clarity) into single spaces - will the macro run and reduce the spaces in the cell from 50 to 25, and then proceed to the next cell and perform the function there, or if it reduces the number of spaces to 25, and detects that there are more spaces, it will continue to delete them until there are none left.

Steve
 
The short answer to your question is that a VBA code will only be performed one time. If you want it performed more, then you need to code a loop. Some of the other responses were trying to either come up with an efficient loop, or sometimes specific situations can avoid a loop.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
The short answer to your question is that a VBA code will only be performed one time. If you want it performed more, then you need to code a loop. Some of the other responses were trying to either come up with an efficient loop, or sometimes specific situations can avoid a loop.

I see.

Thank you
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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