|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
各位我利用VBA自定义EXCEL公式取发生数没有数据,损益类科目不行呢?查了下如果是“平”的就无法取,请大侠指点啊。代码如下:
Function FS(acode As String, Period As String, j As String, SQdb As String, Ye As String) As Double
'求 借方发生额 (--科目--月份--方向--帐套--年度--)
'需记帐
'适用多个会计科目
Dim Cn As ADODB.Connection, rs As ADODB.Recordset
Dim Db As String, MyTable As String, CnStr As String, SqlStr As String
Dim myArray1() As String
Dim i, m As Byte
Application.Volatile True '定义为易失函数 只要包含此函数的单元格中出现计算过程,此函数都将重新进行计算。
Set Cn = New ADODB.Connection
Db = "UFDATA_" & SQdb & "_" & Ye '数据库名称
MyTable = "GL_accsum" '科目总账--表名称
ipIDpwd '获取服务器IP 等
CnStr = "provider=sqloledb;server=" & SvrIP & ";user id=" & LoginID & ";pwd=" & LoginPWD & ";database=" & Db
Cn.Open CnStr
myArray1 = strPass(acode)
m = UBound(myArray1)
FS = 0
For i = 1 To m
acode = myArray1(i)
SqlStr = "SELECT md,mc FROM " & MyTable & " WHERE ccode=" & acode & " and iperiod=" & Period
Set rs = Cn.Execute(SqlStr)
If rs.BOF And rs.EOF Then
FS = 0 + FS
Else
If j = "借" Then
FS = rs.Fields(0).Value + FS
Else:
FS = rs.Fields(1).Value + FS
End If
End If
Set rs = Nothing
Next i
Cn.Close
Set Cn = Nothing
Set rs = Nothing
End Function
|
|