A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
We can calculate the offset value for the difference between the 2 columns and use that like this:
Sub PlayWithTableLists()
Dim anyCell As Range
Dim tbl As ListObject
Dim Actual As ListColumn
Dim Credits As ListColumn
Dim Total As Long ' change type as needed
'this will hold offset from Credits column to Actual column
Dim offset2Actual As Integer
Set tbl = Sheets("Data").ListObjects("Table1")
Set Actual = tbl.ListColumns("actual")
Set Credits = tbl.ListColumns("credits")
'Calculate offset from Credits to Actual
offset2Actual = Actual.Range.Column - Credits.Range.Column
'this should work for numeric entries
For Each anyCell In Credits.Range
If IsNumeric(anyCell) Then
MsgBox "Credit = " & anyCell & vbCrLf & "Actual = " & anyCell.Offset(0, offset2Actual)
'Total = Total + creditsValue * actualValue
Total = Total + anyCell * anyCell.Offset(0, offset2Actual)
End If
Next
MsgBox "The Total is " & Total
'just good houskeeping - release assigned resources
'back to the system for reuse
Set tbl = Nothing
Set Actual = Nothing
Set Credits = Nothing
End Sub