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
[TABLE="width: 64"]
<tbody>[TR]
[TD="class: xl90, width: 64"]1[/TD]
[/TR]
[TR]
[TD="class: xl90"]5[/TD]
[/TR]
[TR]
[TD="class: xl90"]39[/TD]
[/TR]
[TR]
[TD="class: xl90"]1[/TD]
[/TR]
[TR]
[TD="class: xl90"]1[/TD]
[/TR]
[TR]
[TD="class: xl90"]4[/TD]
[/TR]
[TR]
[TD="class: xl90"]36[/TD]
[/TR]
[TR]
[TD="class: xl90"]0[/TD]
[/TR]
</tbody>[/TABLE]

But macro gives the following answer

[TABLE="width: 64"]
<tbody>[TR]
[TD="class: xl90, width: 64"]1[/TD]
[/TR]
[TR]
[TD="class: xl90"]6[/TD]
[/TR]
[TR]
[TD="class: xl90"]45[/TD]
[/TR]
[TR]
[TD="class: xl90"]46[/TD]
[/TR]
[TR]
[TD="class: xl90"]47[/TD]
[/TR]
[TR]
[TD="class: xl90"]51[/TD]
[/TR]
[TR]
[TD="class: xl90"]87[/TD]
[/TR]
[TR]
[TD="class: xl91"]87[/TD]
[/TR]
</tbody>[/TABLE]

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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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,224,812
Messages
6,181,083
Members
453,021
Latest member
Justyna P

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