【发布时间】:2011-12-04 05:52:42
【问题描述】:
我有一个文档,我将根据用户的个人需求,将其分发给具有任意行数(相同列数)的三个不连续组的用户。 我当前的宏运行速度很慢,所以我想知道是否有人可以提出比我这里更好的解决方案,或者至少为我指出内置函数可能有助于我正在做的事情的方向。
在下面的脚本中,我将其设置为作用于以下行中的数据:6、8-19、21-60、63-81。
所有这一切都是为了删除第一列数据 (sFirstCol = "D") 中的值,并将适用行中所有列 (E->AC) 中的值移动到左侧一个单元格,将最右边的列值留空。
Sub RollOver1()
Dim sFirstCol As String
Dim sSecCol As String
Dim sSLastCol As String
Dim sLastCol As String
Dim iFirstRow As Integer
Dim iLastRow As Integer
Dim excludeRows() As Variant
sFirstCol = "D"
sSecCol = "E"
sSLastCol = "AB"
sLastCol = "AC"
iFirstRow = 6
iLastRow = 81
excludeRows = Array(7, 20, 61, 62)
For i = iFirstRow To iLastRow
Dim bExcludedRow As Boolean
bExcludedRow = False
For Each eR In excludeRows
If eR = i Then
bExcludedRow = True
End If
Next
If bExcludedRow = False Then
Range(sSecCol + LTrim(Str(i)) + ":" + sLastCol + LTrim(Str(i))).Select
Selection.Copy
Range(sFirstCol + LTrim(Str(i)) + ":" + sSLastCol + LTrim(Str(i))).Select
ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, IconFileName:=False
Range(sLastCol + LTrim(Str(i))).Select
Selection.ClearContents
End If
Next
Range(sFirstCol + LTrim(Str(iFirstRow + 1))).Select
ActiveCell.FormulaR1C1 = "='Sheet1'!R[4]C[2]"
Range(sLastCol + LTrim(Str(iFirstRow))).Select
ActiveCell.FormulaR1C1 = "=RC[-1]+7"
Range("A1").Select
End Sub
【问题讨论】: