2016-11-17 50 views
0

我必須在Excel中拼寫數字,但我需要美分形式爲「xx/100」 Ex。 3,258.63 =「三千二百五十捌佰63/100 ONLY」如何將SpellNumber宏函數的美分形式更改爲「xx/100」

現在我的微距功能


OPTION EXPLICIT 
    'MAIN FUNCTION 

'=SPELLNUMBER(95) 
SUB TEST() 
    MSGBOX SPELLNUMBER(95) 
END SUB 

FUNCTION SPELLNUMBER(MYNUMBER, OPTIONAL BMONEY = FALSE) 
    DIM DOLLARS, CENTS, TEMP 
    DIM DECIMALPLACE, COUNT 
    DIM INUMBER 

    REDIM PLACE(9) AS STRING 
    PLACE(1) = " HUNDRED " 
    PLACE(2) = " THOUSAND " 
    PLACE(3) = " MILLION " 
    PLACE(4) = " BILLION " 
    PLACE(5) = " TRILLION " 

INUMBER = MYNUMBER 
' STRING REPRESENTATION OF AMOUNT. 
MYNUMBER = TRIM(STR(MYNUMBER)) 

' POSITION OF DECIMAL PLACE 0 IF NONE. 
DECIMALPLACE = INSTR(MYNUMBER, ".") 
' CONVERT CENTS AND SET MYNUMBER TO DOLLAR AMOUNT. 
IF DECIMALPLACE > 0 THEN 
    CENTS = GETTENS(LEFT(MID(MYNUMBER, DECIMALPLACE + 1) & _ 
    "00", 2)) 
    MYNUMBER = TRIM(LEFT(MYNUMBER, DECIMALPLACE - 1)) 
END IF 

COUNT = 1 
DO WHILE MYNUMBER <> "" 
    TEMP = GETHUNDREDS(RIGHT(MYNUMBER, 3)) 
    IF TEMP <> "" THEN DOLLARS = TEMP & PLACE(COUNT) & DOLLARS 
    IF LEN(MYNUMBER) > 3 THEN 
     MYNUMBER = LEFT(MYNUMBER, LEN(MYNUMBER) - 3) 
    ELSE 
     MYNUMBER = "" 
    END IF 
    COUNT = COUNT + 1 
LOOP 

IF BMONEY = TRUE THEN 
    SELECT CASE DOLLARS 
    CASE "" 
     DOLLARS = "NO DOLLARS" 
    CASE "ONE" 
     DOLLARS = "ONE DOLLAR" 
    CASE ELSE 
    DOLLARS = DOLLARS & " DOLLARS" 
END SELECT 

SELECT CASE CENTS 
    CASE "" 
    CENTS = " AND NO CENTS" 
    CASE "ONE" 
    CENTS = " AND ONE CENT" 
    CASE ELSE 
    CENTS = " AND " & CENTS & " CENTS" 
END SELECT 
END IF 
SPELLNUMBER = DOLLARS & CENTS 
END FUNCTION 


FUNCTION GETHUNDREDS(BYVAL MYNUMBER) 
    DIM RESULT AS STRING 
    IF VAL(MYNUMBER) = 0 THEN EXIT FUNCTION 
    MYNUMBER = RIGHT("000" & MYNUMBER, 3) 
    ' CONVERT THE HUNDREDS PLACE. 
    IF MID(MYNUMBER, 1, 1) <> "0" THEN 
     RESULT = GETDIGIT(MID(MYNUMBER, 1, 1)) & " HUNDRED " 
    END IF 
    ' CONVERT THE TENS AND ONES PLACE. 
    IF MID(MYNUMBER, 2, 1) <> "0" THEN 
     RESULT = RESULT & GETTENS(MID(MYNUMBER, 2)) 
    ELSE 
     RESULT = RESULT & GETDIGIT(MID(MYNUMBER, 3)) 
    END IF 
    GETHUNDREDS = RESULT 
END FUNCTION 

FUNCTION GETTENS(TENSTEXT) 
    DIM RESULT AS STRING 
    RESULT = "" ' NULL OUT THE TEMPORARY FUNCTION VALUE. 
    IF VAL(LEFT(TENSTEXT, 1)) = 1 THEN ' IF VALUE BETWEEN 10-19... 
     SELECT CASE VAL(TENSTEXT) 
      CASE 10: RESULT = "TEN" 
      CASE 11: RESULT = "ELEVEN" 
      CASE 12: RESULT = "TWELVE" 
      CASE 13: RESULT = "THIRTEEN" 
      CASE 14: RESULT = "FOURTEEN" 
      CASE 15: RESULT = "FIFTEEN" 
      CASE 16: RESULT = "SIXTEEN" 
      CASE 17: RESULT = "SEVENTEEN" 
      CASE 18: RESULT = "EIGHTEEN" 
      CASE 19: RESULT = "NINETEEN" 
      CASE ELSE 
     END SELECT 
    ELSE ' IF VALUE BETWEEN 20-99... 
     SELECT CASE VAL(LEFT(TENSTEXT, 1)) 
      CASE 2: RESULT = "TWENTY " 
      CASE 3: RESULT = "THIRTY " 
      CASE 4: RESULT = "FORTY " 
      CASE 5: RESULT = "FIFTY " 
      CASE 6: RESULT = "SIXTY " 
      CASE 7: RESULT = "SEVENTY " 
      CASE 8: RESULT = "EIGHTY " 
      CASE 9: RESULT = "NINETY " 
      CASE ELSE 
     END SELECT 
     RESULT = RESULT & GETDIGIT _ 
      (RIGHT(TENSTEXT, 1)) ' RETRIEVE ONES PLACE. 
    END IF 
    GETTENS = RESULT 
END FUNCTION 

FUNCTION GETDIGIT(DIGIT) 
    SELECT CASE VAL(DIGIT) 
     CASE 1: GETDIGIT = "ONE" 
     CASE 2: GETDIGIT = "TWO" 
     CASE 3: GETDIGIT = "THREE" 
     CASE 4: GETDIGIT = "FOUR" 
     CASE 5: GETDIGIT = "FIVE" 
     CASE 6: GETDIGIT = "SIX" 
     CASE 7: GETDIGIT = "SEVEN" 
     CASE 8: GETDIGIT = "EIGHT" 
     CASE 9: GETDIGIT = "NINE" 
     CASE ELSE: GETDIGIT = "" 
    END SELECT 
END FUNCTION 

但是,讓我在仙拼寫以及,我怎樣才能以50/100的格式離開美分?

非常感謝您的幫助

回答

0

這將有助於獲得小數部分。

Right(FormatCurrency(MYNUMBER, 2), 2) & "/100" 
+0

這將在小數函數輸入?我沒有關於vba宏的背景。我事先做了appologize,並且感謝 – AFab

+0

這個功能在哪裏?許多許多非常感謝 – AFab

0

' POSITION OF DECIMAL PLACE 0 IF NONE. 
DECIMALPLACE = INSTR(MYNUMBER, ".") 
' CONVERT CENTS AND SET MYNUMBER TO DOLLAR AMOUNT. 
IF DECIMALPLACE > 0 THEN 
    CENTS = RIGHT(FORMATCURRENCY(MYNUMBER, 2), 2) & "/100" 
    MYNUMBER = TRIM(LEFT(MYNUMBER, DECIMALPLACE - 1)) 
END IF 

由於@Barney小數功能是能夠顯示爲 50/100(例如)

相關問題