I apologise, I realise this may have been asked a gazillion times already but I've tried looking and I can't find a situation like mine. I'm still learning, and I've never posted here before either so please be gentle with me.
I am working in Excel VBA. I have two cells (PICKAmt and INVAamt, same sheet) and they each have the exact same number in them, e.g. 399.80.
Even after formatting the cell to 0.00 VBA still reads them both as "399.8", but also still says they are not the same
They are both "Doubles"
This same calculation worked under the exact same circumstances on a different sheet
My code says:
Private Function INVACalc(ByVal INVAamt As Double, Holdcell As String, lastcell1 As String) As Double Dim PICKAmt As Double Dim APSDamt As Double Dim lastcell3 As String Dim SUND As String Dim APIE As String Worksheets("GL").Activate Range(lastcell1).Offset(0, 9).NumberFormat = "0.00" Range(lastcell1).Offset(0, 9).Value = Application.WorksheetFunction.Sum(Range("AL:AL")) 'add up total of all lines PICKAmt = Range(lastcell1).Offset(0, 9).Value If PICKAmt = INVAamt Then 'do stuff Else 'do something else End if
It goes straight to the "Else", as if the two amounts are not identical, which they are. They have no extra spaces or characters. The only difference I can pick up between them is that the INVAAmt cell is formatted as "Custom" and the PICKAmt cell is formatted as "Number", but again, this same code does the job just fine on other sheets with the same formatting. I am at a loss.