0

以下 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
4

1 回答 1

1

Shift:=xlToLeft正在尝试使用命名参数。这在 VBScript 中是不可能的。您必须定义 xlToLeft (Const) 并确保您xlToLeft在正确的位置传递(使用 VBA 文档检查 .Delete 参数的数量和顺序)。

附言

如果您在 Google 上搜索“vbscript delete xltoleft”,那么第一次点击就会对您有所帮助。

于 2012-12-16T07:09:49.330 回答