返回列表 上一主題 發帖

把Excel 資料匯出為純文字 並填入固定值

本帖最後由 stillfish00 於 2015-2-3 16:37 編輯

回復 1# zero1019
如果要補零的都是數字可以用format函數就好,如果還包含字母,可以自己寫...
  1. Function FillStrZero(strIn As String, digit As Integer, Optional fromLeft As Boolean = True) As String
  2.   If Len(strIn) > digit Then Err.Raise vbObjectError + 9999, , "String length should not larger than " & digit & "digit."
  3.   FillStrZero = IIf(fromLeft, String(digit - Len(strIn), "0") & strIn, strIn & String(digit - Len(strIn), "0"))
  4. End Function
複製代碼
test
  1. Sub Test()
  2.   MsgBox [A2] & FillStrZero([B2], 8) & FillStrZero([C2], 5, False) & FillStrZero(Round([D2] * 1000), 9) & FillStrZero(Round([E2] * 1000), 9)
  3. End Sub
複製代碼
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。

TOP

        靜思自在 : 人生最大的成就是從失敗中站起來。
返回列表 上一主題