VBA Fast Convert # to Text add ' Before Number

VenturSum

Board Regular
Joined
May 23, 2010
Messages
138
Programmers,

I REALLY need your your Help speeding up some code.

In one worksheet a table has 70,000 rows.

In column "Q" (17), 40,000 cells have numbers; 30,000 are empty rows.

I need to convert these numbers into text
by adding a single quote (') before each number.

My code sorts the table in Column Q A-Z,
So the numbers are at the top
Then loop through each column:

Code:
lRow = 2
Do While .cells(lRow, 17).value <> ""

   .cells(lRow, 17).value  = "'" & .cells(lRow, 17).value 

   lRow = lRow + 1
Loop

Can you provide any other method to yield the same result??

Respectfully,

John Annapolis, MD
 
Rick,

EVALUATE() ... That may be the answer.
As say be the array.
I'll test these strategies when I get to work.

BTW.. I love it when by boss says "How do you know so much??"
I smile and think of our Mr. Excel community.


Thank you,
John
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Rick,

THANK YOU!! from 40 minutes to < 3 seconds.

Here is my final code, I used the sheet's code name
and adjusted the last row.

Code:
Sub PrefixAnApostophe()
Dim lRowLast As Long

    With wsTransactions
        lRowLast = .Cells(1, 17).End(xlDown).Row
        With .Range("Q2", "Q" & lRowLast)
              .Value = Evaluate(Replace("IF(@="""","""",""'""&@)", "@", .Address))
        End With
    End With
End Sub


Respectfully,

John in Annapolis
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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