以下VBScript代码在“
行给出错误 .Range(.Cells(lRow, lCol), .Cells(lRow, lCol + 3)).Delete Shift:=xlToLeft
的 CORRECT 的
.Range(.Cells(lRow, lCol), .Cells(lRow, lCol + 3)).Delete(-4159)
错误是:“预期声明结束”。
的 CODE 的
Sub DataShiftFromRightToLeft(Ob6)
Dim lCol,COL_FIRST,startCol
Dim NUM_TASKS:NUM_TASKS=36
COL_FIRST = objExcel1.Application.WorksheetFunction.Match("Parent Business Process ID", ob6.Rows(1), 0)
COL_FIRST=COL_FIRST+1
'Set wst = Ob6.ActiveSheet
With ob6.ActiveSheet
For lRow = 2 To .UsedRange.Rows.Count
lTask = 1
Do While lTask <= NUM_TASKS
lCol = COL_FIRST + (lTask - 1) * 4
If Len(.Cells(lRow, lCol).Value) = 0 And _
Len(.Cells(lRow, lCol + 1).Value) = 0 And _
Len(.Cells(lRow, lCol + 2).Value) = 0 And _
Len(.Cells(lRow, lCol + 3).Value) = 0 Then
' make sure there is something to the right to shift over
If .Cells(lRow, lCol).End(xlToRight).Column < .Columns.Count Then
' delete the empty cells and shift everything left``
.Range(.Cells(lRow, lCol), .Cells(lRow, lCol + 3)).Delete Shift:=xlToLeft
Else
' force the loop to the next row
lTask = NUM_TASKS + 1
End If
Else
lTask = lTask + 1
End If
Loop
Next lRow
End With
End Sub
答案 0 :(得分:1)
您的Shift:=xlToLeft
正在尝试使用命名参数。这在VBScript中是不可能的。您必须定义xlToLeft(Const)并确保将xlToLeft
传递到正确的位置(使用VBA Docs检查.Delete参数的数量和顺序)。
<强> P.S。强>
如果你谷歌搜索“vbscript delete xltoleft”,the first hit会帮助你。