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