从工作表中查找值并将第1页中的行复制到工作表2

时间:2017-04-11 08:51:20

标签: excel-vba vba excel

我现在尝试这个代码,并在目的地给我一个错误。我不知道我做错了什么。我尝试了几次,现在是一个非常不同的事情。

Sub Find_First()

    Dim FindString As String
    Dim Rng As Range
    Dim RowCnt As Long

    FindString = Sheets("sheet1").Range("F5").Value

    If Trim(FindString) <> "" Then
        With Sheets("sheet2").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
            If Not Rng Is Nothing Then

            RowCnt = Rng.Row

            Worksheets("sheet1").Range("p13:af13").Copy Destination:=Worksheets("sheet2").Range(Cells(RowCnt, 1))




                Application.Goto Rng, True
            Else
                MsgBox "Nothing found"
            End If
        End With
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

假设您要在Sheet1的A列中搜索字符“X”,如果找到,请将该行复制并粘贴到Sheet2,然后运行下面的脚本。

[Test]
public void ConnectToSourceFile_ValidUri_Connection_TimeOut_Throws_WebException()
{
  Uri uriForTheFileToDownload = new Uri("https://suppose/this/is/valid/url.txt");

  FileConnectorHttp fileConnectorOverHttp = new FileConnectorHttp(uriForTheFileToDownload);

  Assert.Throws(Is.TypeOf<WebException>(),

    () => fileConnectorOverHttp.ConnectToFile());

}

这就是你想要的吗?