Forum

Summing 3 columns a...
 
Notifications
Clear all

Summing 3 columns and results another column

2 Posts
2 Users
0 Reactions
72 Views
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Hi,

 

I have spreadsheet with long list import every month columns "E" = subtotal "F" = GST, "G" = QST , "H"= HST and  fifth column "J" total

 

how can I modify the code below to add those columns above and put the total in column "J",

 

here is the code:

 

Sub SumByArray()
Dim arrayColA As Variant, arrayColB As Variant, arrayColC As Variant 'must be declared as variants.
Dim iArrayIndex As Long, dblArrayItemColA As Double, dblArrayItemColB As Double, dblArrayItemColC As Double

arrayColA = Sheet1.Range("E2:E1000")
arrayColB = Sheet1.Range("F2:F1000")
arrayColC = Sheet1.Range("J2:J1000")

For iArrayIndex = 1 To 10
dblArrayItemColA = arrayColA(iArrayIndex, 1)
dblArrayItemColB = arrayColB(iArrayIndex, 1)
dblArrayItemColJ = dblArrayItemColA + dblArrayItemColB
arrayColC(iArrayIndex, 1) = dblArrayItemColC
Next iArrayIndex

Sheet1.Range("J2:J1000") = arrayColC
End Sub

 

I tried but doesn't work just put "0" values in column "J"

 

than you,

 
Posted : 07/01/2022 2:04 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Jose,

Why are you using VBA for this?  Just use a formula in Column J?

If you are using Power Query to import the data every month, use that to perform the calculation then write the data out to your worksheet.

Regards

Phil

 
Posted : 11/01/2022 4:01 am
Share: