Vba 如何:在一张图纸上检索列中的最后一个单元格,然后粘贴到另一张图纸上
我正在使用VBA进行一个会计项目,我对它还很陌生 简短版本:用户在excel单元格A12、B12中输入名称(名称)和$Transaction Amount(tran) 我在A28:D32上有一个表,包含名称和帐户值。名称在a列,帐户值在D列 我想根据存款人的姓名将交易金额添加到D列的正确行中Vba 如何:在一张图纸上检索列中的最后一个单元格,然后粘贴到另一张图纸上,vba,excel,finance,Vba,Excel,Finance,我正在使用VBA进行一个会计项目,我对它还很陌生 简短版本:用户在excel单元格A12、B12中输入名称(名称)和$Transaction Amount(tran) 我在A28:D32上有一个表,包含名称和帐户值。名称在a列,帐户值在D列 我想根据存款人的姓名将交易金额添加到D列的正确行中 E.G Transaction: name: Charles Transaction Amount: $500 Before Charles $2154 John $3150 Chris
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
试试这个:
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
我假设,每个名称的值存储在名称旁边(右侧),如果不是这样,您需要相应地更改
偏移量
值您可以告诉我们名称和金额存储在哪些列中吗?另外,您是否总是在A12和B12中记录姓名和交易金额?太好了。谢谢只需再偏移几列,直到D。