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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,214,552
Messages
6,120,172
Members
448,948
Latest member
spamiki

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