- 1, 16)) ''''Hj3 = CurrencyToStr(Hj2) For i = 2 To X - 2 Hj1 = Hj1 + Val(.TextMatrix(i, 15)) If Val(.TextMatrix(i, 16)) > 0 Then Hj2 = Hj2 + Val(.TextMatrix(i, 15)) * Val(.TextMatrix(i, 16)) End If Next i If Hj2 <= A1 Or Hj2 >= A2 Then GoTo ErrTransact End If Hj3 = CurrencyToStr(Hj2) .TextMatrix(X, 2) = Hj1 .Cell(flexcpText, X, 3, X, 15) = IIf(Hj3 = "", " ", Hj3) .Cell(flexcpText, X, 16, X, 17) = Format(Hj2, "¥0.00") .Cell(flexcpAlignment, X, 2, X, 14) = flexAlignLeftCenter ''''.Select X, 3 ''''.CellAlignment = flexAlignLeftCenter If SelRow > 1 And SelCol > 0 Then .Select SelRow, SelCol End With Exit Sub ErrTransact: MsgBox "你输入的数字过大无法计算!请修改!!!" End Sub ------------------------------------------------ 将数字转换为大写金额的函数: Function CurrencyToStr(ByVal Number As Currency) As String Number = Val(Trim(Number)) If Number = 0 Then CurrencyToStr = "": Exit Function Dim str1Ary As Variant, str2Ary As Variant str1Ary = Split("零 壹 贰 叁 肆 伍 陆 柒 捌 玖") str2Ary = Split("分 角 元 拾 佰 仟 万 拾 佰 仟 亿 拾 佰 仟 万 拾 佰") Dim a As Long, b As Long ''''循环基数 Dim tmp1 As String ''''临时转换 Dim tmp2 As String ''''临时转换结果 Dim Point As Long ''''小数点位置 If Number <= -922337203685477# Or Number >= 922337203685477# Then Exit Function End If tmp1 = Round(Number, 2) tmp1 = Replace(tmp1, "-", "") ''''先去掉“-”号 Point = InStr(tmp1, ".") ''''取得小数点位置 If Point = 0 Then ''''如果有小数点,最大佰万亿 b = Len(tmp1) + 2 ''''加2位小数 Else b = Len(Left(tmp1, Point + 1)) ''''包括点加2位小数 End If ''''''''先将所有数字替换为中文 For a = 9 To 0 Step -1 tmp1 = Replace(Replace(tmp1, a, str1Ary(a)), ".", "") Next For a = 1 To b b = b - 1 If Mid(tmp1, a, 1) <> "" Then If b > UBound(str2Ary) Then Exit For tmp2 = tmp2 & Mid(tmp1, a, 1) & str2Ary(b) End If Next If tmp2 = "" Then CurrencyToStr = "": Exit Function ''''''''〓下面为非正式财务算法,可以去掉〓 For a = 1 To Len(tmp2) tmp2 = Replace(tmp2, "零亿", "亿零") tmp2 = Replace(tmp2, "零万", "万零") tmp2 = Replace(tmp2, "零仟", "零") tmp2 = Replace(tmp2, "零佰", "零") tmp2 = Replace(tmp2, "零拾", "零") tmp2 = Replace(tmp2, "零元", "元") tmp2 = Replace(tmp2, "零零", "零") tmp2 = Replace(tmp2, "亿万", "亿") Next ''''''''〓上面为非正式财务算法,可以去掉〓 If Point = 1 Then tmp2 = "零元" + tmp2 If Number < 0 Then tmp2 = "负" + tmp2 If Point = 0 Then tmp2 = tmp2 + "整" CurrencyToStr = tmp2 End Function ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Cell 属性的使用: Cell 的作用是给以选定区块的特定的设置值,具体值可参阅相应属性值。 语法:Cell(条件准则, Row1, Col1, Row2, Col2) = 相应准则值 其中的“条件准则”有以下准则常数,根据准则的不同而设置相应准则的值: flexcpAlignment 对齐方式 flexcpBackColor 背景色 flexcpChecked 选择框 flexcpCustomFormat 格式设置 flexcpData 日期 flexcpFloodColor 颜色 flexcpFloodPercent 背景色 flexcpFont 字体 flexcpFontBold 粗体 flexcpFontItalic 斜体 flexcpFontName 字体名 flexcpFontSize 字体大小 flexcpFontStrikethru 删除线 flexcpFontUnderline 下划线 flexcpFontWidth 字符宽 flexcpForeColor 字符色 flexcpHeight 高 flexcpLeft 左 flexcpPicture 添加图 flexcpPictureAlignment 图对齐 flexcpRefresh 刷新 flexcpSort 分类 flexcpText 字符 flexcpTextDisplay 显示字符 flexcpTextStyle 文本样式 flexcpTop 返回顶端高,同 RowPos 和 valueMatrix 属性 flexcpvalue 返回字符值 flexcpVariantvalue 返回字符值 flexcpWidth 返回单元宽 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ flexSTSum 方法:每行增加小计行[这个方法还不会用]语法: VSG.flexSTSum 常数名, [GroupOn As Long], :标签列 [TotalOn As Long], :计算列 [Format As String], :格式,例 "$0.00" [BackColor As Color], :Color [ForeColor As Color], :Color [FontBold As Boolean], :False|True [Caption As String], :例 "数 %s" [MatchFrom As Integer], :0|1|2|3 [TatalOnly As Boolean] :False|True 常数名: 常数 常数值 说明 flexSTNone 0 大纲唯一的,没有合计价值 flexSTClear 1 清除全部的小计 flexSTSum 2 总数 flexSTP