Skip a column and and add - VBA

adnan1975

New Member
Joined
Aug 24, 2017
Messages
38
Hello,
i am trying to do a simple task with VBA but code is not working. I need to add Column N,Q,T.... In other words every 3 column
i have the following code

PHP:
For lrow = 7 To 15
For xcol = 14 To 78 Step 3
'sumx = 0
sumx = sumx + Cells(lrow, xcol).Value
Next xcol
md.Cells(lrow, 79).Value = sumx
Next lrow

The macro runs but it doesn't give me the right answer. for example the answer in column 79 or 'CA' should be following
1
5
39
1
1
4
36
0

<tbody>
</tbody>

But macro gives the following answer

1
6
45
46
47
51
87
87

<tbody>
</tbody>

which means it adds each row from top to bottom in column 79. I am not sure how to fix it.
Any help is much appreciated.

Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try moving the sumx=0 line
Code:
For Lrow = 7 To 15
   For xCol = 14 To 78 Step 3
      sumx = sumx + Cells(Lrow, xCol).Value
   Next xCol
   md.Cells(Lrow, 79).Value = sumx
   sumx = 0
Next Lrow
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,308
Messages
6,124,178
Members
449,146
Latest member
el_gazar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top