Loop and formulas

Jeeremy7

Board Regular
Joined
May 13, 2020
Messages
110
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone :),

For the explanation I inserted a picture I'll be referring to so it'll be easier

What I would like to do is for code 010102 (A2) to take the total of all the amounts in column G and to put it on the same row as 010102
Then do the same thing for all the other codes

The problem is that I don't know how to do a LOOP macro and it's not a fixed amount of line for every code..

I will later on change the 010102 with the text to a cell with only 01-0102 but I could probably figure that out

The biggest issue is to find to SUM formula to work and to loop ....

A big thanks in advance for whoever will take the time to help me :biggrin:
 

Attachments

  • Macro.PNG
    Macro.PNG
    26.7 KB · Views: 5

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Is it ok to put the sum on the same row as the "Total Itemxxx"?
 
Upvote 0
You mean that The total for 010102 would be on G9 ?

If so, that would be ok as long as I have the code on the same row
In this case the code would be on cell E9 "Total Item 010102", I would just create a formula after to convert it on 01-0102

I hope I answered your question !
 
Upvote 0
OK, how about
VBA Code:
Sub jeeremy()
   Dim Rng As Range
   
   For Each Rng In Range("G:G").SpecialCells(xlConstants, xlNumbers).Areas
      Rng.Offset(Rng.Count).Resize(1).Formula = "=sum(" & Rng.Address & ")"
   Next Rng
End Sub
 
Upvote 0
Solution
Wow thanks ! :biggrin:
So are the loop formula not a necessity ? Because your technique is a lot faster it seems

I will try the rest on my own see if I improved I may post an other thread soon haha
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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