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
[TABLE="width: 362"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD] sigma1[/TD]
[TD]Constant[/TD]
[TD] Linear[/TD]
[/TR]
[TR]
[TD]0.557-0.048M[/TD]
[TD]-0.557[/TD]
[TD]-0.048[/TD]
[/TR]
[TR]
[TD]0.599-0.054M[/TD]
[TD]-0.599[/TD]
[TD]-0.054[/TD]
[/TR]
[TR]
[TD]0.562-0.047M[/TD]
[TD]-0.562[/TD]
[TD]-0.047[/TD]
[/TR]
[TR]
[TD]0.492-0.035M[/TD]
[TD]-0.492[/TD]
[TD]-0.035[/TD]
[/TR]
[TR]
[TD]0.549-0.044M[/TD]
[TD]-0.549[/TD]
[TD]-0.044[/TD]
[/TR]
</tbody>[/TABLE]
But the terms (when given more format space) are actually like this:
[TABLE="width: 235"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.5569999814[/TD]
[TD]-0.0480000004[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.5989999771[/TD]
[TD]-0.0540000014[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.5619999766[/TD]
[TD]-0.0469999984[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.4920000136[/TD]
[TD]-0.0350000001[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.5490000248[/TD]
[TD]-0.0439999998[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="width: 362"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD] sigma1[/TD]
[TD]Constant[/TD]
[TD] Linear[/TD]
[/TR]
[TR]
[TD]0.557-0.048M[/TD]
[TD]-0.557[/TD]
[TD]-0.048[/TD]
[/TR]
[TR]
[TD]0.599-0.054M[/TD]
[TD]-0.599[/TD]
[TD]-0.054[/TD]
[/TR]
[TR]
[TD]0.562-0.047M[/TD]
[TD]-0.562[/TD]
[TD]-0.047[/TD]
[/TR]
[TR]
[TD]0.492-0.035M[/TD]
[TD]-0.492[/TD]
[TD]-0.035[/TD]
[/TR]
[TR]
[TD]0.549-0.044M[/TD]
[TD]-0.549[/TD]
[TD]-0.044[/TD]
[/TR]
</tbody>[/TABLE]
But the terms (when given more format space) are actually like this:
[TABLE="width: 235"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.5569999814[/TD]
[TD]-0.0480000004[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.5989999771[/TD]
[TD]-0.0540000014[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.5619999766[/TD]
[TD]-0.0469999984[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.4920000136[/TD]
[TD]-0.0350000001[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-0.5490000248[/TD]
[TD]-0.0439999998[/TD]
[/TR]
</tbody>[/TABLE]
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
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