Loading___
New Member
- Joined
- May 27, 2021
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hi all,
Hope You are doing fine in this pandemic season.
So I try to make macro using vba where you can add after the data is input to the sheet
here's what it's look like when the data is input the first time
the button corresponding to the addition some of the cells. If I push the buttons, here's what it looks like
It works fine, so far so good.
but then the problem comes if i have multiple input like this
so after i sum the second time the total getting mixed all the way to the top.
How to set the code so that the sum will start right after this "--------" cell?
Here's the VBA code for this:
Sorry for the long post
Hope You are doing fine in this pandemic season.
So I try to make macro using vba where you can add after the data is input to the sheet
here's what it's look like when the data is input the first time
the button corresponding to the addition some of the cells. If I push the buttons, here's what it looks like
It works fine, so far so good.
but then the problem comes if i have multiple input like this
so after i sum the second time the total getting mixed all the way to the top.
How to set the code so that the sum will start right after this "--------" cell?
Here's the VBA code for this:
VBA Code:
Sub Total()
Dim LastRow As Long, LastCol As Long, Total As Long
Dim StartRow As Long
Dim StartRange As Range
Dim workingSheet As Worksheet
Set workingSheet = ThisWorkbook.Sheets("Sheet1")
With workingSheet
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
StartRow = .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row).End(xlUp).Row
.Cells(LastRow + 1, 5).Value = "Total: "
.Cells(LastRow + 1, 6).Value = "=SUM(F" & StartRow + 2 & ":F" & LastRow & ")"
.Cells(LastRow + 1, 7).Value = "=SUM(G" & StartRow + 2 & ":G" & LastRow & ")"
.Cells(LastRow + 1, 8).Value = "=SUM(H" & StartRow + 2 & ":H" & LastRow & ")"
.Cells(LastRow + 1, 10).Value = "=SUM(J" & StartRow + 2 & ":J" & LastRow & ")"
.Cells(LastRow + 1, 11).Value = "=SUM(K" & StartRow + 2 & ":K" & LastRow & ")"
.Cells(LastRow + 1, 12).Value = "=SUM(L" & StartRow + 2 & ":L" & LastRow & ")"
.Cells(LastRow + 1, 13).Value = "=SUM(M" & StartRow + 2 & ":M" & LastRow & ")"
.Cells(LastRow + 1, 1).Value = "---------"
.Cells(LastRow + 1, 2).Value = "---------"
.Cells(LastRow + 1, 3).Value = "---------"
.Cells(LastRow + 1, 4).Value = "---------"
.Cells(LastRow + 1, 9).Value = "---------"
.Cells(LastRow + 2, 1).Value = "---------"
.Cells(LastRow + 2, 2).Value = "---------"
.Cells(LastRow + 2, 3).Value = "---------"
.Cells(LastRow + 2, 4).Value = "---------"
.Cells(LastRow + 2, 5).Value = "---------"
.Cells(LastRow + 2, 6).Value = "---------"
.Cells(LastRow + 2, 7).Value = "---------"
.Cells(LastRow + 2, 8).Value = "---------"
.Cells(LastRow + 2, 9).Value = "---------"
.Cells(LastRow + 2, 10).Value = "---------"
.Cells(LastRow + 2, 11).Value = "---------"
.Cells(LastRow + 2, 12).Value = "---------"
.Cells(LastRow + 2, 13).Value = "---------"
End With
End Sub
Sorry for the long post