Using Excel as an Adding Machine
Hi
Below is a response I posted to another similar question recently.
The poster wanted to accumulate data over the month . The total appeared in
cell B3, and they were entering data in the cell below this. Column A showed
the date.
You may be able to modify this to suit your needs
original post
Please take good note of all the warnings given about using a single cell
accumulator.
The following code will give the "appearance" of what you want, whilst
maintaining an audit trail of all values entered.
Using a change event code on the worksheet, will add the value entered in
Cells B4:B34 in B3.
It will then hide row 4, fill in the next date in A5 and B5 will be the next
row to enter data.
Each time you enter a value, the same procedure will occur, so you are
always entering you new data immediately below cell B3, but it's actual
location will keep changing.
Format cell A3 FormatCellsNumberCustommmmm
Enter in cell B3 = SUM(B4:B34)
At the end of the month, mark rows 3:35Right clickUnhide.
Mark cells A4:B35Delete and this will clear down all of the data for the
month. Enter a new Month date in cell A3 and start all over again.
At any time, you can unhide the rows and view all of the data that has been
entered. When you have finished looking, just hide rows 4 through to the
last row where data has been entered in column B.
Copy the code belowright click on your sheet tabView codePaste the code
into the white pane.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lrow As Long
lrow = Cells(Rows.Count, "B").End(xlUp).Row
If Target.Count 1 Then Exit Sub
If Target.Row < 4 Then Exit Sub
If Target.Column < 2 Then Exit Sub
If Target.Value = 0 Then
Select Case MsgBox _
("Did you mean to enter a value of Zero?", _
vbYesNo Or vbQuestion Or vbDefaultButton1, _
"Zero Value Entered")
Case vbYes
Case vbNo
Target.Value = ""
Cells(lrow + 1, 2).Select
Exit Sub
End Select
End If
Application.ScreenUpdating = False
Application.EnableEvents = False
Cells(lrow, 1) = Format(Cells(3, 1) + lrow - 4, "dd-mmm")
Cells(lrow + 1, 1) = Format(Cells(3, 1) + lrow - 3, "dd-mmm")
Cells(lrow, 1).EntireRow.Hidden = True
Cells(lrow + 1, 2).Select
endsub:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
--
Regards
Roger Govier
"preston-ahp" wrote in message
...
I am wanting to utilize essentially an adding machine function in an Excel
spreadsheet. I can't, presently, find a way to input a number in a cell,
have
it included in a total, and then enter another number to be added to that
recently increased sum (just like an adding machine).
|