如果任何一组单元格使用 VBScript 为空白而不使用任何循环技术,是否有更快的过程将组中的单元格值从右向左移动?(将每一行的数据打包,向左)
输入表: *
Project# T1Name T1StartDate T1FinishDate T2Name T2StartDate T2FinishDate T3Name T3StartDate T3FinishDate
11 S1 12/7/2012 19/7/2012 S2 12/7/2012 19/7/2012
12 S2 12/6/2012
13 S4 11/05/12 S6 12/5/10
输出表:
Project# T1Name T1StartDate T1FinishDate T2Name T2StartDate T2FinishDate T3Name T3StartDate T3FinishDate
11 S1 12/7/2012 19/7/2012 S2 12/7/2012 19/7/2012
12 S2 12/6/2012
13 S4 11/05/12 S6 12/05/10
更新了我的输出表 请检查,首先它放错地方了!
更新1
Project# T1Name T1StartDate T1FinishDate T2Name T2StartDate T2FinishDate T3Name T3StartDate T3FinishDate
10 S1 11/5/2011 S2 5/5/2011
11 S1 11/5/2011 5/4/2011 S1 11/5/2011 5/4/2011
更新2
Project# T1Name T1StartDate T1FinishDate T2Name T2StartDate T2FinishDate T3Name T3StartDate T3FinishDate
11 11/5/2011 S1 11/5/2011 5/4/2011 S2 11/5/2011 5/4/2011
将此条目添加到未正确移动的表中。你能检查一下吗?
更新代码:
Option Explicit
Dim objExcel1,objWorkbook
Dim strPathExcel1
Dim objSheet1,IntRow1
Dim Task,Totltask
Dim DataArray(14),index,Counter
Set objExcel1 = CreateObject("Excel.Application")
strPathExcel1 = "D:\VA\TestVBSScripts\Test.xlsx"
Set objWorkbook=objExcel1.Workbooks.open(strPathExcel1)
Set objSheet1 = objExcel1.ActiveWorkbook.Worksheets(1)
IntRow1=2
Do While objSheet1.Cells(IntRow1,1).Value <> ""
Totltask=2
index=0
Do Until Totltask> 10
'MsgBox("Hi")
If objSheet1.Cells(IntRow1,Totltask).Value <> "" Or objSheet1.Cells(IntRow1,Totltask+1).Value <> "" Or objSheet1.Cells(IntRow1,Totltask+2).Value <> "" Then
DataArray(index)=objSheet1.Cells(IntRow1,Totltask).Value
DataArray(index+1)=objSheet1.Cells(IntRow1,Totltask+1).Value
DataArray(index+2)=objSheet1.Cells(IntRow1,Totltask+2).Value
index=index+3
End If
Totltask=Totltask+3
Loop
Totltask=2
Counter=index-1
index=0
'MsgBox(Counter)
Do While index < Counter
'MsgBox("Hi")
objSheet1.Cells(IntRow1,Totltask).Value=DataArray(index)
objSheet1.Cells(IntRow1,Totltask+1).Value=DataArray(index+1)
objSheet1.Cells(IntRow1,Totltask+2).Value=DataArray(index+2)
Totltask=Totltask+3
index=index+3
Loop
Erase DataArray
Do Until Totltask >10
objSheet1.Cells(IntRow1,Totltask).Value=""
Totltask=Totltask+1
Loop
IntRow1=IntRow1+1
Loop
'=======================
objExcel1.ActiveWorkbook.SaveAs strPathExcel1
objExcel1.Workbooks.close
objExcel1.Application.Quit
'======================
***如果可能的话,任何机构都可以建议我应该如何让它更快?这段代码是正确的,可以根据需要产生输出。但是太慢了。