我需要这样做:
我在Excel中使用常规自动填充功能(双击单元格侧面的点)将内容复制到子单元格,因此在这种情况下单击单元格A1中的点将执行以下操作: / p>
我需要一个脚本,它将在整个列中重复该过程,直到相邻单元格中没有更多值。
答案 0 :(得分:6)
您可以通过键盘执行此操作...
要删除公式,请选择A列,复制和粘贴特殊值。
答案 1 :(得分:2)
大概这就是你要找的东西:
Option Explicit
Sub FillInTheBlanks()
Dim StartCell As Range, EndCell As Range
Set StartCell = ActiveCell
Set EndCell = ActiveSheet.Cells(ActiveSheet.UsedRange.Rows.Count + 1, StartCell.Offset(0, 1).Column).End(xlUp)
Dim currentText As String
Dim i As Long
For i = StartCell.Row To EndCell.Row
If Not IsEmpty(ActiveSheet.Cells(i, StartCell.Row)) Then
currentText = ActiveSheet.Cells(i, StartCell.Row).Text
Else
ActiveSheet.Cells(i, StartCell.Row).Value = currentText
End If
Next i
End Sub
该代码执行以下操作:
如果你真的想要截图中的内容,那么你需要这样做:
Option Explicit
Sub FillInTheBlanks()
Dim StartCell As Range, EndCell As Range, NextCell As Range
Set StartCell = ActiveCell
Set EndCell = Cells(ActiveSheet.UsedRange.Rows.Count + 1, StartCell.Offset(0, 1).Column).End(xlUp)
While StartCell.Row < EndCell.Row
Set NextCell = StartCell.Offset(1, 1).End(xlDown).Offset(0, -1)
StartCell.AutoFill Destination:=ActiveSheet.Range(StartCell, NextCell), Type:=xlFillDefault
Set StartCell = NextCell.Offset(1, 0)
Wend
End Sub
这是做什么的: