首页 > 解决方案 > 插入列和自动填充列标题的宏

问题描述

我想在表格之间插入两列,并从“I12”自动填充到“J12”。我设法通过记录宏来添加列,但我想自动填充列,直到“评论”列之前。我无法记录宏,因为插入的列数可能会有所不同。

8 在此处输入图像描述] 1

Sub column_insert()
    'Range("Table1[[#Headers],[Inspection Tool (ID '#-Due Date)]:[Comment]]").Column.Insert
    Dim headerColumn As Long
    Dim headerColumn4 As Long
    headerColumn = Cells.Find(What:="Comment").Column
    'MsgBox (headerColumn)
    
    For i = 1 To 2
        Columns(headerColumn).Insert
    Next i
    
    Dim headerColumn2 As Long
    
    headerColumn2 = Cells.Find(What:="Comment").Column - 1
    'MsgBox (headerColumn2)
    Dim LastColumn As Long
    LastColumn = Cells(12, Columns.Count).End(xlToLeft).Column
    
    Range("Table1[[#Headers],[Sample 1]:[Result ]]").Select
    Selection.AutoFill Destination:=Range(Range("J12"), Cells(12, headerColumn2)), Type:=xlFillDefault
    

End Sub

有人可以帮助使用以前列中的公式自动填充新插入的列吗?

标签: excelvbaexcel-formula

解决方案


推荐阅读