Simple macro to save a copy of a spreadsheet, and increment version number by 0.1
Excel is adding spurious numbers onto the version number. E.g. If I start with 0.1 after the macro I get not 0.2 but 0.200000002980232 in the cell.
Which in this context is annoying, as the version number gets written to some files generated by the sheet and it looks wierd, but I can easily imagine some other applications where it could be a critical fault.
Changing the type of CurrentVersion to Double cures it but I'd like to know whats going on. Is it a bug in VBA?
Excel 2007, if thats relevant.
Code:
Dim Frontsheet As Worksheet Dim CurrentVersion As Single Set Frontsheet = Worksheets("Dashboard") CurrentVersion = Frontsheet.Cells(5, 4).Value CurrentVersion = CurrentVersion + 0.1 ActiveWorkbook.Save ActiveWorkbook.SaveCopyAs ActiveWorkbook.Path & "\MPR Mapping" & "." & Format(CurrentVersion, "00.0") & ".xlsm" Frontsheet.Cells(5, 4).Value = CurrentVersion Frontsheet.Cells(6, 4).Value = Now()
Which in this context is annoying, as the version number gets written to some files generated by the sheet and it looks wierd, but I can easily imagine some other applications where it could be a critical fault.
Changing the type of CurrentVersion to Double cures it but I'd like to know whats going on. Is it a bug in VBA?
Excel 2007, if thats relevant.
Comment