我有一个范围需要向右移动以适应新的范围。 我将列名(A,B,C,D)保存在不同的工作表中,在我移动此范围后,我需要通过添加52来更新此工作表中的列名,而不是(A,B,C,D)它现在将是(BA,BB,BC,BD)
由于某种原因,我一直在超出范围错误。
Coln = wsSetup.Range("A1:T1")
ReDim ColP(UBound(Coln), UBound(Coln, 2))
ColP(xi + 1, xj) = Split(Columns(Coln(xi, xj) + 52).Address(), "$")(2) 'get column letter
Coln(xi + 1, xj) = Coln(xi, xj) + 52
答案 0 :(得分:1)
所以你需要将列52列向右切割和粘贴?
Sub tgr()
Dim wsSetup As Worksheet
Dim Coln As Range
Set wsSetup = ActiveWorkbook.Sheets("Sheet1")
Set Coln = wsSetup.Range("A1:T1")
Coln.Cut Coln.Offset(, 52)
End Sub
或者您的意思是列标题字面上是" A"," B"," C"等等,您需要将它们更新为&#34 ; BA"," BB"," BC"等?
Sub tgr()
Dim wsSetup As Worksheet
Dim Coln As Variant
Dim i As Long
Dim lCellsToRight As Long
Set wsSetup = ActiveWorkbook.Sheets("Sheet1")
lCellsToRight = 52
Coln = wsSetup.Range("A1:T1").Value
For i = LBound(Coln, 2) To UBound(Coln, 2)
Coln(1, i) = Replace(wsSetup.Cells(1, Coln(1, i)).Offset(, lCellsToRight).Address(0, 0), 1, vbNullString)
Next i
wsSetup.Range("A1:T1").Value = Coln
End Sub