JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,676
- Office Version
- 365
- Platform
- Windows
I want to write a little function to compare the amount of sodium in several products. The data is currently in a text string of the form: Xg Ymg, where X is one serving of the product and Y is the amount of sodium in that serving. I need to extract the X and Y then calculate Y/X. The text string might also be blank. Here's some sample data:
Is there a simple way to extract those values in VBA?
Is there a simple Excel expression that will extract the two numerical values and pass them to the UDF? I suppose I'd have to make the parameters optional in order to be able to handle the blank case.
Book1 | ||||
---|---|---|---|---|
C | D | |||
4 | 28.35g 0mg | 0.00 | ||
5 | 28.35g 0mg | 0.00 | ||
6 | 28g 135mg | 4.82 | ||
7 | ||||
8 | 28g 135mg | 4.82 | ||
9 | 28g 135mg | 4.82 | ||
10 | 28g 65mg | 2.32 | ||
11 | ||||
12 | 28g 110mg | 3.93 | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D4:D5 | D4 | =0/28.35 |
D6,D8:D9 | D6 | =135/28 |
D10 | D10 | =65/28 |
D12 | D12 | =110/28 |
Is there a simple way to extract those values in VBA?
Is there a simple Excel expression that will extract the two numerical values and pass them to the UDF? I suppose I'd have to make the parameters optional in order to be able to handle the blank case.