Copy value based on decimal place position

Bernieg

Board Regular
Joined
Jan 1, 2009
Messages
146
Office Version
  1. 365
Platform
  1. Windows
I have a variable called USL with a value of 3.36
Trying to split the values as below, no rounding

Thanking you in advance

Bernie


VBA Code:
USL = "3.36"

'I only want the digits left of the decimal & the first one after the decimal
'I.E. Pete = 3.3

'I only want the second digit after the decimal
'Pat = 6
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You're passing a string to USL so you can use string functions like
- Left (where the length to take from the left is found by using Instr to find the decimal point and subtract 1) to get 3, or 33 or 333 or whatever.
- Right (only taking one from the right)
However, if you made a mistake by making USL a string and it should remain a number data type, then ignore that. I think that's important before anyone can provide a precises answer. Your sample data is very limited as well. What if the value is 3.367? You still want the 2nd after the decimal (6) or the last (7) because in your example, 6 is also the last?
 
Upvote 0
I've noticed an error in the suggestion. It would return 3 from 3.36 or 33 from 33.6 so would need to be adjusted to include the first character after the dot/decimal. That is a simple matter of adding 1 to the position of the decimal.
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,733
Members
449,185
Latest member
hopkinsr

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