2017-03-22 5 views
0

"L"열의 수량을 나타내는 수식을 가진 명명 된 범위 "수량"(워크 시트 Sheet1, 셀 I21 : L28) 있습니다. 열 L에서 값> 0을 검색하고 그 값을 열 K의 데이터와 함께 다른 워크 시트 (Sheet10)에 붙여 넣으려고합니다. 다음 코드는 닫을 수 있지만 값이 아닌 수식을 붙여 넣습니다. 도와주세요.다른 워크 시트의 Vlaues 붙여 넣기 조건에 따라 명명 된 범위에서 복사 할 VBA

Sub CopyOnCondition() 
    Dim sh1 As Worksheet, sh2 As Worksheet, c As Range 
    Set sh1 = Sheet1 'Edit sheet name 
    Set sh2 = Sheet10 'Edit sheet name 
    With sh1 
     For Each c In .Range("L18:L24") 
      If c.Value > 0 Then 
       c.Copy sh2.Cells(Rows.Count, 1).End(xlUp)(2, 1) 
      End If 
     Next 
    End With 
End Sub 

답변

0

아래 코드 열만 K의 값을 복사한다 시도 : L을 때 열 L의 값>

Sub CopyOnCondition() 

    Dim sh1 As Worksheet, sh2 As Worksheet, c As Range 
    Set sh1 = Sheet1 'Edit sheet name 
    Set sh2 = Sheet10 'Edit sheet name 

    With sh1 
     For Each c In .Range("L18:L24") 
      If c.Value > 0 Then 
       c.Offset(, -1).Resize(1, 2).Copy '<-- copy column K with L 
       ' paste values to the first empty row in Column A of sh2 
       sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial xlValues 
      End If 
     Next c 
    End With 

End Sub 
+0

굉장해! 매력처럼 작동합니다. 고맙습니다 –

1

Sub CopyOnCondition() 
    Dim sh1 As Worksheet, sh2 As Worksheet, c As Range 
    Set sh1 = Sheet1 'Edit sheet name 
    Set sh2 = Sheet10 'Edit sheet name 
    With sh1 
     For Each c In .Range("L18:L24") 
      If c.Value > 0 Then 
       sh2.Cells(Rows.Count, 1).End(xlUp)(2, 1).resize(,2).value=c.offset(,-1).resize(,2).value 
      End If 
     Next 
    End With 
End Sub 
+1

을'sh2.Cells 0 (Rows.Count, 1)'이 충분하지 않다면'sh2'가없는'Rows.Count'는'ActiveSheet'를 찾고 있다는 것을 의미합니다. 또한 PO는 열 K : L의 값을 복사하려고합니다. 코드는 열 K의 값만 복사합니다. –

+0

@ShaiRado -이를 지적 해 주셔서 감사합니다. – SJR

+0

이것도 효과가 있습니다. 결과의 차이를 말할 수는 없습니다. 둘 다 고마워. –