Sub AddNumbersOnOneRow
Const s_Field_ColA = "ColumnA"
Const s_Field_ColB = "ColumnB"
Const s_Field_ColC = "ColumnC"
Const s_Field_ColD = "ColumnD"
Dim iPsDepth As Integer
Dim iPsColA As Integer
Dim iPsColB As Integer
Dim iPsColC As Integer
Dim iPsColD As Integer
Dim lRow As Long
Dim dDepth As Double
Dim ColumnD As Double
'------------------------
'Determine the field positions of the necessary fields in the array.
If InitFieldsFnB(gs_Depth, iPsDepth, _
s_Field_ColA, iPsColA, _
s_Field_ColB, iPsColB, _
s_Field_ColC, iPsColC) _
Then
'One or more of the required fields missing from the table.
Exit Sub
End If
With gINTRules.GridData
iPsDepth = .FieldCol("Depth")
iPsColA = .FieldCol("ColumnA")
iPsColB = .FieldCol("ColumnB")
iPsColC = .FieldCol("ColumnC")
iPsColD = .FieldCol("ColumnD")
For lRow = 1 To glNumRows
ColumnD= CDbl(gsDataA(iPsColA, lRow))+ CDbl(gsDataA(iPsColB, lRow))
gsDataA(iPsColD, lRow)= CStr(ColumnD)
Next lRow
End With
End Sub
当我运行这个宏时,我没有收到任何错误。但是,这个宏没有给我答案,D列中什么也没有。
我想把 A 列和 B 列的加法放到 D 列![这是我的表,我想把 A 列和 B 列的加法放到 D 列。但是当我运行宏时,我什么也得不到。]
我怀疑以下几行给我带来了麻烦:
For lRow = 1 To glNumRows
ColumnD= CDbl(gsDataA(iPsColA, lRow))+ CDbl(gsDataA(iPsColB, lRow))
gsDataA(iPsColD, lRow)= CStr(ColumnD)
Next lRow
任何帮助是极大的赞赏!!!
我的主要子是:
'#LibInclude "common procedures"
Option Explicit
Public Sub Main
Dim gsDataA As Variant
Dim glNumRows As Integer
With gINTRules.GridData
'Put the grid data into a working string data array.
gsDataA = .DataArray
glNumRows = UBound(gsDataA, 2)
'Put the modified data array back into the input grid.
.DataArray = gsDataA
'Success is True if there were no errors.
gINTRules.Success = CBool(.ErrorCol = 0)
End With
End Sub