以下 VBScript 代码在该行给我一个错误“
.Range(.Cells(lRow, lCol), .Cells(lRow, lCol + 3)).Delete Shift:=xlToLeft
正确的
.Range(.Cells(lRow, lCol), .Cells(lRow, lCol + 3)).Delete(-4159)
错误是:“预期语句结束”。
代码
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