如何通过在VBA中使用范围来选择已标识的单元格

时间:2014-01-31 05:56:16

标签: excel vba excel-vba

Dim coname, WHAT_TO_FIND As String
    Dim i As Integer
    totalRow = Application.CountA(Range("c:c")) - 1
    i = 2
    While i <= totalRow
    coname = Sheet20.Cells(i, "A") 
    i = i + 1
    WHAT_TO_FIND = coname
    sheets("Sheet21").Select 
    Set ws = ActiveSheet
    Set FoundCell = ws.Range("D:D").Find(what:=WHAT_TO_FIND, lookat:=xlWhole)

    wend

// in sheet20 I have limited number of comapny names list
// in sheet21 I have the data with n number of company names

请让我知道如何选择在sheet21中找到的特定单元格。

1 个答案:

答案 0 :(得分:1)

尝试避免使用.Select INTERESTING READ

但是要回答您的问题,请将此代码粘贴到

下面
Set FoundCell = ws.Range("D:D").Find(what:=WHAT_TO_FIND, lookat:=xlWhole)
If Not FoundCell Is Nothing Then FoundCell.Select

我宁愿使用这个

Set FoundCell = ws.Range("D:D").Find(what:=WHAT_TO_FIND, lookat:=xlWhole)
If Not FoundCell Is Nothing Then
    With FoundCell
        '
        '~~> Do something
        '
    End With
End If