在Excel工作表的每一行中查找特定字符串

sh7euo9m  于 2022-12-01  发布在  其他
关注(0)|答案(1)|浏览(185)

我有一个Excel工作表,其中的数据是像“输入表”。我需要使用VBscript搜索,如果T1或T2存在于每一行。如果它被找到,那么“任务compdate”列应该复制值从其直接的“Stardate”列的下一个任务,如果有的话。

输入工作表:

Activity        Task1    Task1 Stardate   Task1 Compdate     Task2     Task2 Stardate   Task2 Compdate   Task3     Task3 Stardate   Task3 Compdate

A1                T1       02/01/2012                           T1       04/01/2011                         T3         09/02/2011

A2                T2       02/01/2012                           T2       04/01/2011                         T3         09/02/2011

A3                T1       02/01/2012                           T4       04/01/2011                         T3         09/02/2011

输出工作表:

Activity        Task1    Task1 Stardate   Task1 Compdate     Task2     Task2 Stardate   Task2 Compdate   Task3     Task3 Stardate   Task3 Compdate

A1                T1       02/01/2012        04/01/2011         T1        04/01/2011       09/02/2011       T3         09/02/2011

A2                T2       02/01/2012        04/01/2011         T2        04/01/2011       09/02/2011       T3         09/02/2011

A3                T1       02/01/2012        04/01/2011         T4        04/01/2011                        T3         09/02/2011

更新代码:

IntRow6=2

Do While objSheet6.Cells(IntRow6,1).Value <> ""

DataCount=0
 For DataCount=0 to UBound(VMHArray)

  Set rSearch = objSheet6.Cells(IntRow6,1).EntireRow
  Set rFound = rSearch.Find(VMHArray(DataCount))
     
        If Not rFound Is Nothing Then

                 adrFirst = rFound.Address

               Do  

                   objSheet6.Cells(IntRow6,rFound.Column + 2)= objSheet6.Cells(IntRow6,rFound.Column + 5)
                   Set rFound = rSearch.FindNext(rFound)

               Loop Until rFound.Address = adrFirst
       End If
    
 Next

IntRow6=IntRow6+1
Loop
hi3rlvi2

hi3rlvi21#

更新代码:

IntRow6=2

Do While objSheet6.Cells(IntRow6,1).Value <> ""

DataCount=0
 For DataCount=0 to UBound(VMHArray)

  Set rSearch = objSheet6.Cells(IntRow6,1).EntireRow
  Set rFound = rSearch.Find(VMHArray(DataCount))
     
        If Not rFound Is Nothing Then

                 adrFirst = rFound.Address

               Do  

                   objSheet6.Cells(IntRow6,rFound.Column + 2)= objSheet6.Cells(IntRow6,rFound.Column + 5)
                   Set rFound = rSearch.FindNext(rFound)

               Loop Until rFound.Address = adrFirst
       End If
    
 Next

IntRow6=IntRow6+1
Loop

相关问题