搜索单元格未提及特定字符串

时间:2017-12-08 15:15:12

标签: excel vba

我有一些代码目前在A列中搜索提及27并将B列中的单元格复制到C列中的同一行。有没有办法修改此代码以复制27时的单元格值不在A栏中。这有意义吗?

样本工作表包含单元格中的数字27(A1:A30)和单元格中的数字1(B1:B30);除了A5,它是28,而B5,它是2。 我知道,在这种情况下,我可以搜索28,但这个代码的主要原因是将有超过1个值可能不同,即26或22,以及30等。

当我考虑这个时,我认为我必须将行If Not foundCel Is Nothing Then更改为不同的行,但我可能会在这里咆哮错误的树。

Option Explicit

Sub Button1_Click()

    Dim v As Long

    v = 1
    findStr = "27"
    Set foundCel = Range("A:A").Find(What:=findStr)

    If Not foundCel Is Nothing Then              'Yes'

        firstAddress = foundCel.Address

        Do

            Range("C" & v).Value = foundCel.Offset(0, 1).Value
            Set foundCel = Range("A:A").FindNext(foundCel)
            v = v + 1

        Loop While Not foundCel Is Nothing And foundCel.Address <> firstAddress

    End If

End Sub

感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:1)

在这里,测试27不存在于column1(A)的字符串中,如果不存在则将column2(B)复制到column3(C):

 (function(){

  angular.module('app').directive('myDirective', function(){
     return {
       .............
       controller : MyDirectiveController,
       .............
     }
  });

  MyDirectiveController.$inject = ['$scope'];

  function MyDirectiveController ($scope) {

  }

})();

快速而肮脏。干杯。 -WWC