When placing data into cells using VBA, I get a strange result.
Using the code below (trimmed extensively for this example) I get the following results…
– Place a “Single” value of “68.4” into a cell. The cell displays “68.4” but when I check, it actually contains the value “68.4000015258789”
Can anyone tell me why?
Sub Example()
‘ Convert a string value to a Single and place in a cell
Dim intRow As Integer
Dim strPart As String
Dim sglDistance as Single
intRow = 2
strPart = “68.4”
sglDistance = CSng(strPart)
‘ Single step through and
‘ sglDistance does equal “68.4”
‘ Place the data into a cell
With ActiveSheet
.Range(“E” & intRow).Value = sglDistance
End With
‘ Check the cell value
‘ Displays as 68.4
‘ Contains 68.4000015258789
End Sub
An explanation would be appreciated.