2013-12-16 1 views
0

프로젝트 작업 중일 때 시트간에 특정 데이터를 복사하려는 지점이 있습니다. 예 : 열 "A"에 셀에 "Hello"이 포함되어 있으면 셀 "E4"에있는 내용을 복사하십시오. "IF"진술이 효과가 있습니까?Excel VBA - 특정 이름이 하나의 워크 북에서 일치 할 때 셀 범위 복사 및 붙여 넣기

내가 지금까지 내 프로젝트에 대한이 코드는

Sub testfortito() 
    Dim x As Workbook 
    Dim y As Workbook 
    Dim ws As Worksheet 

    'this opens both workbooks 
    Set x = Workbooks.Open("Location1") 
    Set y = Workbooks.Open("Location2") 

    'to do the copy 
    x.Sheets("sheet3").Range("A2:AC2").Copy 

    For Each ws In Worksheets 
     If ws.Name <> "sheet3" Then 
      ws.Range("E3").Copy 
      Worksheets ("Sheet3") 
     End If  
    Next ws 
End Sub 
+0

당신이 정말로 원하는 것은'A 열에서 Find' 원하는 셀의'Address''에있다 '를 클릭 한 다음 해당 '열 E'의 내용을 복사하십시오. –

+0

본질적으로 예 –

답변

0

는 시도이다이

Sub testfortito() 
    Dim colEtxt(), ctr 

    ctr = 0 
    With Sheet1.Range("A:A") 
     Set txt = .Find(What:="hello", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _ 
     SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) 
     If Not txt Is Nothing Then 
      firstAddress = txt.Address 
      Do 
       ReDim Preserve colEtxt(ctr) 
       colEtxt(ctr) = Range(txt.Address).Offset(0, 4).Value 
       Set txt = .FindNext(txt) 
       ctr = ctr + 1 
      Loop While Not txt Is Nothing And txt.Address <> firstAddress 
     End If 
    End With 

    'copy the array onto sheet2 using transpose technique 
    Sheet2.Range("A1:A" & UBound(colEtxt) + 1) = WorksheetFunction.Transpose(colEtxt) 
End Sub 
+0

고마워요. 무슨 일이 벌어지는 지 알 겠어요. 현재 이걸 치기 전에 현재 프로 시저에 갇혀 있습니다. 이 내용을 시험해 볼 수있게 되 자마자 나는 이것이 작동하는지 알려 줄 것입니다. –

관련 문제