我正在使用VBA进行会计项目,而且我对它很陌生。
简短版本:用户输入名称(名称)和$ Transaction Amount(tran)到excel单元格A12,B12
我在A28:D32上有一个表,其中包含名称和帐户值。名称在A列中,帐户值在D中。
我想根据存款人的姓名将交易金额添加到D栏中的正确行。
E.G
Transaction:
name: Charles
Transaction Amount: $500
Before
Charles $2154
John $3150
Chris $8450
After
Charles $2654
John $3150
Chris $8450
下面是乱七八糟的东西,我想出来是不行的。
请帮助谢谢!!
Sub Step3UpdateEquity()
Dim name As String
Dim tran As Integer
Dim pretranIvalue As Integer
Dim PosttranIvalue As Integer
name = Range("A12").Value
tran = Range("B12").Value
PosttranIvalue = pretranIvalue + tran
Set Depositcell = Range("A28:D32").Find(pretranIvalue)
Range("Depositcell.adress").Value = PosttranIvalue
End Sub
答案 0 :(得分:1)
试试这个:
Sub Step3UpdateEquity()
Dim name As String
Dim tran As Integer
Dim DepositCell As Range
name = Range("A12").Value
tran = Range("B12").Value
Set DepositCell = Range("A28:D32").Find(name).Offset(0, 1)'Asuming that the Transaction
'amount is located in the cell
'on the right of the name cell
DepositCell.Value = DepositCell.Value + tran
End Sub
我假设,每个名称的值都存储在名称旁边(右侧),如果不是这样,则需要相应地更改Offset
值