[英]How to insert/copy in Excel base on number of another column in Excel VBA or not
[英]Excel VBA Insert Column with standard name + number
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
我有一个工作表,我想在该列的顶部插入一个名称为“调整 #”的列。 每次运行宏时,我都希望它是调整 1、调整 2、调整 3 等......
这怎么可能? 我可以插入列,但我无法弄清楚如何使名称每次都增加数量。 谢谢!
好吧,根据您的问题和提供的代码 - 这是可能的解决方案:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.