I'm very new to VBA. I wrote this UDF (my first proper bit of coding) and I'm screwing something up, but I don't know what. I know very little and am currently taking a course, but most answers seem interchangeable to my uneducated eyes.
Also, if anyone has any tips on reducing numbers of variables or cleaning up code in general, I would greatly appreciate it.
Function NearestEighth(number) As String
Dim NE As String
WholeNum = Application.WorksheetFunction.RoundDown(number, 0)
DecNum = (number) - (WholeNum)
Near = Round(DecNum * 8, 0) / 8
Select Case Near
Case Is = 0
NE = ""
Case Is = 0.125
NE = "1/8"
Case Is = 0.25
NE = "1/4"
Case Is = 0.375
NE = "3/8"
Case Is = 0.5
NE = "1/2"
Case Is = 0.625
NE = "5/8"
Case Is = 0.75
NE = "3/4"
Case Is = 0.875
NE = "7/8"
End Select
Prelim = (number)
Select Case Prelim
Case Prelim > 0 And Prelim < 1
FractionFormat = NE
Case Prelim > 1
FractionFormat = (WholeNum) & "-" & (NE)
End Select
NearestEighth = FractionFormat
End Function
