I have imported strings that represent simple equations with a constant and a linear term. I want to split them apart so that I can used them for more calculations. It should look like this
<colgroup><col><col><col></colgroup><tbody>
</tbody>But the terms (when given more format space) are actually like this:
<colgroup><col><col></colgroup><tbody>
</tbody>The VBA code reads the first column as a string then splits the string and converts them to single precision. That is when I apply the Round function in VBA as shown in the snippet below
sigma1 | Constant | Linear |
0.557-0.048M | -0.557 | -0.048 |
0.599-0.054M | -0.599 | -0.054 |
0.562-0.047M | -0.562 | -0.047 |
0.492-0.035M | -0.492 | -0.035 |
0.549-0.044M | -0.549 | -0.044 |
<colgroup><col><col><col></colgroup><tbody>
</tbody>
-0.5569999814 | -0.0480000004 | |||
-0.5989999771 | -0.0540000014 | |||
-0.5619999766 | -0.0469999984 | |||
-0.4920000136 | -0.0350000001 | |||
-0.5490000248 | -0.0439999998 |
<colgroup><col><col></colgroup><tbody>
</tbody>
Code:
Sub SplitString()
Dim wksdata As Worksheet
Dim c1 As Single, c2 As Single
Dim row As Integer
Dim sigma As String
Set wksdata = ActiveSheet
For row = 4 To 8
sigma = wksdata.Cells(row, 7) 'Get string
c1 = Round(CSng(Left(sigma, 6)), 3) 'constant
c2 = Round(CSng(Mid(sigma, 6, 6)), 3) 'linear
wksdata.Cells(row, 8) = c1 'numbers into cells
wksdata.Cells(row, 9) = c2 'next to string
Next row
End Sub