Sub 自动生成单据编号()
Dim stName, Rows, num
stName = "数据"
Rows = Sheets(stName).Range("B1").CurrentRegion.Rows.Count '获取行数
Range("B2") = Format(Date, "yyyy-mm-dd") '生成系统时间
With Sheets("付款申请单")
Cells(3, 6).Value = Application.WorksheetFunction.VLookup(Cells(3, 2), Sheets(stName).Range("B2:G" & Rows), 3, 0) '匹配开户行
Cells(4, 2).Value = Application.WorksheetFunction.VLookup(Cells(3, 2), Sheets(stName).Range("B2:G" & Rows), 2, 0) '匹配账号
Cells(5, 2).Value = Application.WorksheetFunction.VLookup(Cells(3, 2), Sheets(stName).Range("B2:G" & Rows), 4, 0) '匹配用途
Cells(7, 8).Value = Application.WorksheetFunction.VLookup(Cells(3, 2), Sheets(stName).Range("B2:G" & Rows), 6, 0) '匹配金额
num = Cells(7, 8).Value
Cells(7, 2).Value = DX(num) '大写
End With
End Sub
Function DX(M) '人民币大写 163字符A 无缺陷 负数显示 “负”
DX = Replace(Replace(Replace(Join(Application.Text(Split(Format(M, " 0. 0 0;负 0. 0 0; ")), ["[DBnum2]"&{0,"","元0角;;元零","0分;;整"}]), a), "零元零", a), "零元", a), "零整", "整")
End Function |