我正在创建一个相当简单的用户表单。用户必须输入我想要计算的2个值,并在Excel中的电子表格中输入一列。
我不确定如何格式化VBA以使其计算这些值,然后将其保存在电子表格中。
这就是我所拥有的:
Private Sub txtRecruitPct_Change()
Dim A As Integer
Dim B As Integer
A = txtApprovedAffs.Value
B = txtEmailsSent.Value
Answer = A / B
End Sub
我需要知道如何将此值计算并保存在Excel中的特定列中。
答案 0 :(得分:1)
如果您要将所有答案转储到#34; A"然后:
Private Sub txtRecruitPct_Change()
Dim A As Integer
Dim B As Integer
Dim LastRow As Long
A = txtApprovedAffs.Value
B = txtEmailsSent.Value
Answer = A / B
LastRow = Range("G" & Rows.Count).End(xlUp).Row
Range("G" & LastRow + 1).Value = Answer
End Sub
如果您希望所有数据都在单独的列中:
Private Sub txtRecruitPct_Change()
Dim A As Integer
Dim B As Integer
Dim LastRow As Long
A = txtApprovedAffs.Value
B = txtEmailsSent.Value
Answer = A / B
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & LastRow + 1).Value = A
Range("B" & LastRow + 1).Value = B
Range("C" & LastRow + 1).Value = Answer
End Sub