The following VBScript code giving me an error at the line”
.Range(.Cells(lRow, lCol), .Cells(lRow, lCol + 3)).Delete Shift:=xlToLeft
CORRECT
.Range(.Cells(lRow, lCol), .Cells(lRow, lCol + 3)).Delete(-4159)
Error is: “Expected End of statement”.
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
Your
Shift:=xlToLeftis trying to use named parameters. This is not possible in VBScript. You have to define xlToLeft (Const) and to make sure that you passxlToLeftat the correct position (use the VBA Docs to check the number and order of the arguments to .Delete).P.S.
If you google for “vbscript delete xltoleft”, the first hit will help you.