Excel – 在图表中的最后一列之后添加多列
我试图在Excel中创build一个macros,将三个列添加到图表的末尾,与图表中的前一列相同,其中一列增加一列。
例如:
Column 1 Column 2 Column 3 Column 4 Column 5 Column 6 PGM Number 1 Amount Notes PGM Number 2 Amount Notes
有没有办法在图表的最后添加三列(PGM号码+1,金额和注释),所以它可以做到以下几点?
Column 7 Column 8 Column 9 Column 10 Column 11 Column 12 PGM Number 3 Amount Notes PGM Number 4 Amount Notes
这是我必须复制最后一列的代码:
Sub InsertColumn() Dim lastColumn As Long lastColumn = ActiveSheet.Range("A1").SpecialCells(xlCellTypeLastCell).Column Columns(lastColumn).Copy Destination:=Columns(lastColumn + 1) End Sub
但显然这是不够的。
感谢您的帮助!
Sub addCols() Dim lastColumn As Long Dim f As String Dim s As String Dim t As String Dim c As Long f = "PGM Number " s = "Amount" t = "Notes" With ActiveSheet lastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column c = (lastColumn + 3) / 3 'assuming first row, otherwise change "1" to desired row .Cells(1, lastColumn + 1) = f & c .Cells(1, lastColumn + 2) = s .Cells(1, lastColumn + 3) = t End With End Sub