添加到列字母的Excel

嗨,我想合并七个单元格一路横跨第1行。而不是Clickng A1按Shift,然后右箭头键六次我想我可以通过macros实现这一点。 我已经写了下面的内容,但是我不确定如何给字母引用添加七个字符,尤其是一旦我进入AA1的最后七个结尾,那么它开始AA2并继续。 下面的代码实现了我想要的,但我怎样才能引入variables和一个循环来存储字母为int,添加六,然后转回到string,并继续下一个集? 我怎么写While (End of row has not been reached)

 Range("A1:G1").Select With Selection .HorizontalAlignment = xlGeneral .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With Range("H1:N1").Select With Selection .HorizontalAlignment = xlGeneral .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With 

这是你正在尝试?

 'R1 is the row of the first cell 'C1 is the column of the first cell 'R2 is the row of the second cell 'C2 is the column of the second cell Sub Sample() Dim Rng As Range Dim ws As Worksheet Dim R1 As Long, C1 As Long Dim R2 As Long, C2 As Long Set ws = ThisWorkbook.Sheets("Sheet1") R1 = 1: C1 = 1 R2 = 1: C2 = C1 + 6 With ws Set Rng = .Range(.Cells(R1, C1), .Cells(R2, C2)) Application.DisplayAlerts = False Rng.Merge Application.DisplayAlerts = True End With End Sub 

编辑 :你也可能会发现这个链接有趣。