Find decimal-formatted and replace with % in a text cell? Maybe RegEx?

LittleGriff

New Member
Joined
Jan 13, 2012
Messages
11
Hello! I have been working on a report, manipulating and formatting various features using VBA. I received a request I haven't heard before.

The exported file contains several columns that contain percentage-formatted values of three or four digits. I'm being asked to join those with text from adjoining text columns, and format the numeric value as a percentage. Of course, when I do the join the percentage is converted to decimals and becomes a string.

The only thing I can think of to try is: find a way to convert the percentage to a string WITH the decimal and % sign in the right places before I do the join, but the numbers in those columns vary widely -- so I can't find and replace individual values. I'm no expert on wildcards, or RegEx, if that's the solution.
Here's a sample of what I get in the raw worksheet:
1.75% (formatted as Percentage) | Of the original amount (this text is in a separate column)

Here's what I get when I do the join:
.0175 (Of the original amount) | (joined into a single cell and I add the parens to the string)

Here's what I'm being asked for:
1.75% (Of the original amount)

Is this even possible?

Thank you so much!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Thanks for your quick reply! I should have included a little code; I'm not seeing a way to use a function to accomplish the formatting.

I'm looping through each row of the columns, creating the join as below, then assigning newString back to overwrite the first cell ("BQ" & i in this case). Let me know if I need to include more code to make my goal clearer.

I have read that Text is a property of the Range object, but I'm having trouble finding examples of Range.Text used "in the wild."

<code>
newString = Worksheets("TEST").Range("BQ" & i).Value & " (" & Worksheets("TEST").Range("BR" & i).Value & ")"
</code>

Thanks again.
 
Upvote 0
Try:

Code:
newString = [COLOR=#0000ff]Format[/COLOR](Worksheets("TEST").Range("BQ" & i).Value, "0.00 %") & " (" & Worksheets("TEST").Range("BR" & i).Value & ")"
 
Upvote 0
This did the trick! Thank you so much. I was really in the weeds on the problem; just could not solve it alone.

Much appreciated!

Maria
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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