我正在尝试创建用于选择范围(A1到A10)的输入框,每当我点击1到10之间的任何单元格时,我想提示输入框输入数字。这就是我所做的,但它没有正常工作,任何建议。我也在THISWORKBOOK下代码module1。
Function Find_Blank_Row() As Double
Dim QtyInput As Double
Dim BlankRow As Long
BlankRow = Range("A10").End(xlUp).Row
QtyInput = InputBox("Enter today expense")
Cells(BlankRow, 1).Font.Bold = True
Cells(BlankRow, 1).Value = QtyInput
End Function
答案 0 :(得分:3)
您必须将代码放入正确的子代码中。这一次,您需要使用Sheet Selection Change事件让每次用户单击某处时运行代码。您还希望确保仅在用户在所需范围内单击时才运行代码。
此外,我认为您的代码还有几个错误,例如没有检查用户输入以确保输入数字,或者没有正确找到第一个空单元格,但您可以自己解决这些问题,或者提出另一个问题。我不确定你需要什么,所以我不会试图解决这些问题。
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim QtyInput As Double
Dim BlankRow As Long
Application.EnableEvents = False
If Target.Column = 1 And Target.Row < 11 Then
BlankRow = Range("A11").End(xlUp).Row
QtyInput = InputBox("Enter today expense")
Cells(BlankRow, 1).Font.Bold = True
Cells(BlankRow, 1).Value = QtyInput
End If
Application.EnableEvents = True
End Sub