I have a program that assembles data one line at a time by user input via a userform. Some of the lines are what I call "Header" lines and need to show the sum of what I call "Detail" lines below them. See the following image as a simplified example:
After a user adds all the detail lines, I need the header to reflect the sum of the detail lines below it until the next header line. So the picture above reflects the end result but prior to running the code the blue cells will be blank. Additionally the number of detail lines can be as little as one with a max of let's say 100. I had the following vba in solution in mind:
^^This code works perfectly to place a formula in the correct spots but that is all it does. lol.
Basically, since only the header line will ever have data in column A I am thinking I can use that to loop through and add some kind of formula to sum only the detail corresponding to the header. Maybe it is not a formula but just more code that can accomplish this. Either way, I would really appreciate some help if you are able to. Thanks!
After a user adds all the detail lines, I need the header to reflect the sum of the detail lines below it until the next header line. So the picture above reflects the end result but prior to running the code the blue cells will be blank. Additionally the number of detail lines can be as little as one with a max of let's say 100. I had the following vba in solution in mind:
VBA Code:
Set rng = Worksheets("GL Import Data Batches").Range("A1:A100")
For Each cell In rng
If cell.Value <> "" Then cell.Offset(0, 2).Formula = "THIS IS WHERE I NEED HELP"
Next cell
^^This code works perfectly to place a formula in the correct spots but that is all it does. lol.
Basically, since only the header line will ever have data in column A I am thinking I can use that to loop through and add some kind of formula to sum only the detail corresponding to the header. Maybe it is not a formula but just more code that can accomplish this. Either way, I would really appreciate some help if you are able to. Thanks!