您好我想将七个单元格一直合并到第1行。而不是单击A1按下shift,然后右箭头键六次我认为我可以通过宏实现这一点。我写了以下但不确定如何在字母引用中添加七个,特别是一旦我进入AA1的最后七个结束,然后它开始AA2并继续。下面的代码实现了我想要的但是如何引入变量和循环来将字母存储为int,添加6,然后转换回字符串并继续下一组?我该怎么写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
答案 0 :(得分:1)
这是你在尝试的吗?
'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
编辑:您可能还会发现THIS链接很有趣。