在我看来,您需要一个只有一个文本框的小型用户表单,一个显示数据输入顺序的范围,例如:
A组 | E | D | F | G
还有一些与表格一起使用的代码,例如:
Dim LastCol As Integer
Dim CurRow As Integer
Private Sub UpdateCells()
Dim Col As Variant
Dim ColumnOrder As Range
'Range that specifies data entry order'
Set ColumnOrder = Range("A3:A15")
LastCol = LastCol + 1
If LastCol > WorksheetFunction.CountA(ColumnOrder) Then
LastCol = 1
CurRow = CurRow + 1
End If
Col = Range("A3").Offset(0, LastCol)
Range(Col & CurRow) = TextBox1.Value
TextBox1 = ""
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
UpdateCells
End If
End Sub
Private Sub UserForm_Initialize()
CurRow = ActiveCell.Row
End Sub
编辑重新评论
在 Excel 中,最后一行可能有点棘手,因为在保存工作簿之前,Excel 不会在删除后更新范围。其中一个可能适合:
Function FindLastRow()
'Assuming that data starts in A1'
r = ActiveSheet.UsedRange.Rows.Count
c = ActiveSheet.UsedRange.Columns.Count
FindLastRow = r
End Function
.
Sub LastRow()
LastRowA = ExecuteExcel4Macro("GET.DOCUMENT(10)")
LastRowB = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
End Sub
更多信息:http ://www.tek-tips.com/faqs.cfm?fid=2115