-1
Sub AddAdjustment()
'
' AddAdjustment Macro
'

Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("D:D").Select
With Range("D13").Select
ActiveCell.FormulaR1C1 = "Adjustment 1"
Range("D13").Select
With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlTop
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
End With
    Range("D18").Select
End Sub

我有一个工作表,我想在列的顶部插入一个名为“Adjustment #”的列。每次我运行宏时,我都希望它是调整 1、调整 2、调整 3 等......

这怎么可能?我可以插入列,但我不知道如何每次都使名称提前。谢谢!

4

1 回答 1

0

好吧,根据您的问题和提供的代码 - 这是可能的解决方案:

Option Explicit

Sub AddAdjustment()
Static colNo As Long

colNo = colNo + 1

Cells(1, 4).EntireColumn.Insert CopyOrigin:=xlFormatFromLeftOrAbove

With Cells(13, 4)
    .Value = "Adjustment " & colNo
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlTop
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    .EntireColumn.AutoFit
End With

    Cells(18, 4).Select

End Sub
于 2020-01-09T20:26:54.010 回答