我在单元格1中写入,然后将鼠标放在该单元格右下角的黑色方块上,右键单击并拖动。
主要问题 - 我不想使用鼠标。并寻找脚本或键盘热键来获得相似的数字
1 3
3 6
5 9
来自关键字
1 3
3 6
答案 0 :(得分:1)
使用箭头键选择包含标题单元格的列部分:
按住 Alt 键并依次触摸 hfis 。然后释放 Alt 键并触摸 Enter 键
..后:
答案 1 :(得分:1)
我将以下宏放在我的个人宏工作簿中并分配了键盘快捷键。
Sub FillSeries()
Dim lFirstBlank As Long
If TypeName(Selection) = "Range" Then
If Selection.Columns.Count = 1 Or Selection.Rows.Count = 1 Then
lFirstBlank = GetFirstBlank(Selection)
If lFirstBlank = 0 Then
SelectAdjacentCol
lFirstBlank = GetFirstBlank(Selection)
End If
If lFirstBlank > 1 Then
If Selection.Columns.Count = 1 Then
Selection.Cells(1).Resize(lFirstBlank - 1).AutoFill _
Selection, xlFillSeries
ElseIf Selection.Rows.Count = 1 Then
Selection.Cells(1).Resize(, lFirstBlank - 1).AutoFill _
Selection, xlFillSeries
End If
End If
End If
End If
End Sub
Function GetFirstBlank(rRng As Range) As Long
Dim i As Long
i = 0
For i = 1 To rRng.Cells.Count
If IsEmpty(rRng.Cells(i)) Then
GetFirstBlank = i
Exit For
End If
Next i
End Function
Sub SelectAdjacentCol()
Dim rAdjacent As Range
If TypeName(Selection) = "Range" Then
If Selection.Column > 1 Then
If Not IsEmpty(Selection.Offset(0, -1).Value) Then
With Selection.Offset(0, -1)
Set rAdjacent = .Parent.Range(.Cells(1), .End(xlDown))
End With
Selection.Resize(rAdjacent.Cells.Count).Select
End If
End If
End If
End Sub
另见http://dailydoseofexcel.com/archives/2008/07/17/fillseries-keyboard-shortcut/
<强>更新强>
如果您只想填充列,并且想要填充选区中的所有列,则以下代码应该执行您想要的操作。它还会查看列中 last 单元格的NumberFormat,并将填充单元格的NumberFormat更改回原始格式。挑选最后一个单元格有点武断,但它就是它。
Sub FillSeriesForAllColumns()
Dim lFirstBlank As Long
Dim rCol As Range
Dim sOldNumberFormat As String
If TypeName(Selection) = "Range" Then
For Each rCol In Selection.Columns
sOldNumberFormat = Selection.Cells(Selection.Cells.Count).NumberFormat
lFirstBlank = GetFirstBlank(rCol)
If lFirstBlank = 0 Then
SelectAdjacentCol
lFirstBlank = GetFirstBlank(rCol)
End If
If lFirstBlank > 1 Then
rCol.Cells(1).Resize(lFirstBlank - 1).AutoFill _
rCol, xlFillSeries
End If
rCol.Offset(lFirstBlank - 1, 0).Resize(rCol.Row - (lFirstBlank - 1)).NumberFormat = sOldNumberFormat
Next rCol
End If
End Sub