-
Solved: Cell Format being Weird
I am using the following code to output to WorkSheets("Data Analysis")
[book attached]
The line in Bold is giving me problems. When it outputs the number to Cell(20,7) it is not obeying the Number Format that is assigned to that cell.
It's weird beause the line preceding the one in bold is nearly identical and it works fine.
[vba]Sub Temperature()
For i = 1 To nRow
For j = 1 To nCol
If T_CFD.Cells(i, j) <> "" And T_CFD.Cells(i, j) <> "$" Then
MyError_T = T_CFD.Cells(i, j) - T_ISX.Cells(i, j)
If Abs(MyError_T) > MyMax_T Then
MyMax_T = Abs(MyError_T)
End If
MyError_T = Abs(MyError_T)
Select Case MyError_T
Case Is <= 5
Within5 = Within5 + 1
Case Is < 10
Within5_10 = Within5_10 + 1
Case Is >= 10
Over10 = Over10 + 1
End Select
ErrorSquare_T = ErrorSquare_T + MyError_T ^ 2
End If
Next j
Next i
TotalObjects = Within5 + Within5_10 + Over10
' *************************************************************************** *****
' *************************************************************************** *****
DataAnalysis.Cells(19, 7) = MyMax_T & " " & Chr(176)
DataAnalysis.Cells(20, 7) = (ErrorSquare_T / TotalObjects) ^ 0.5 & " " & Chr(176)
DataAnalysis.Cells(22, 7) = Within5 / TotalObjects
DataAnalysis.Cells(23, 7) = Within5_10 / TotalObjects
DataAnalysis.Cells(24, 7) = Over10 / TotalObjects
End Sub
[/vba]
The line in question produces:
3.85198375987113 °
-
That's because you are inserting a text format. Create a custom format for the cell to show the degrees
[vba]
Sub Test()
Cells(20, 7) = (100 / 5) ^ 0.5
Cells(20, 7).NumberFormat = "0.00 " & Chr(176)
End Sub
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules