How to speed up the VBA function

Fixed

Board Regular
Joined
Apr 28, 2017
Messages
95
Hello, friends!

I've wrote some function that reduces the strings by the last symbol:

Code:
Function reducer(ByVal txt As String) As String
txt = Left(txt, InStrRev(Left(txt, Len(txt) - 1), Right(txt, 1)))
reducer = txt
End Function

Example:

[TABLE="width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B (function)[/TD]
[TD="align: center"]B (result)[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]a+b+c+d+e+f+g+<strike></strike>[/TD]
[TD]=reducer(A1)<strike></strike>[/TD]
[TD]a+b+c+d+e+f+<strike></strike>[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]11-22-33-44-55-66-77-<strike></strike>[/TD]
[TD]=reducer(A2)<strike></strike>[/TD]
[TD]11-22-33-44-55-66-<strike></strike>[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]11-22-33-44-55-66-<strike></strike>[/TD]
[TD]=reducer(A3)<strike></strike>[/TD]
[TD]11-22-33-44-55-<strike></strike>[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]11-22-33-44-55-<strike></strike>[/TD]
[TD]=reducer(A4)<strike></strike>[/TD]
[TD]11-22-33-44-<strike></strike>[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]11-22-33-44-<strike></strike>[/TD]
[TD]=reducer(A5)<strike></strike>[/TD]
[TD]11-22-33-<strike></strike>[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]11-22-33-<strike></strike>[/TD]
[TD]=reducer(A6)<strike></strike>[/TD]
[TD]11-22-<strike></strike>[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]11-22-<strike></strike>[/TD]
[TD]=reducer(A7)<strike></strike>[/TD]
[TD]11-<strike></strike>[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]11-<strike></strike>[/TD]
[TD]=reducer(A8)<strike></strike>[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

But it works slow when the number of strings > 100k.
How to speed up this function?

Thank you in advance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,224,825
Messages
6,181,190
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