직장에서 숫자 목록을 다른 시트에 복사해야하는 끊임없는 작업이 있습니다. 해당 시트에서 특정 값 (열에서 반복됨)이있는 셀 오른쪽에있는 셀에 해당 숫자를 하나씩 붙여 넣어야합니다. (대상 테이블은 "מודל תגובה"값으로 정렬되며 숨겨진 행이 있습니다.
설명하기 어렵 기 때문에 이미지가 잘 되길 바랍니다.
적절한 코드를 작성하려고했지만 계속 다른 오류가 발생했습니다. 셀 값을 대상 셀에 복사 할 때 문제가 발생하는 것 같습니다.
Dim i As Integer
i = 4
Do While IsEmpty(Cells(i, 1).Value) = False
Worksheets(1).Select
Cells(i, 1).Copy
Worksheets(2).Select
Cells.Find(What:="מודל תגובה", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, -1).Activate
If IsEmpty(ActiveCell.Value) = False Then
Selection.FindNext(After:=ActiveCell).Activate
ActiveCell.Offset(0, -1).Paste
Else
ActiveCell.Offset(0, -1).Select
ActiveCell.Paste
End If
i = i + 1
Loop
엉뚱한 코드 (문자 그대로 내 첫 번째 매크로)에 대해 죄송합니다.
해결책은 필터링 된 범위의 보이는 셀만 반복하는 것입니다.
"מודל תגובה"
이 코드를 실행하기 전에 대상이 필터링되었는지 확인하십시오 . 이 코드를 실행하기 전에 두 번째 이미지처럼 보일 필요가 있습니다.
Dim SourceSheet As Worksheet
Set SourceSheet = Worksheets(1)
Dim DestinationSheet As Worksheet
Set DestinationSheet = Worksheets(2)
Dim LastRow As Long
LastRow = DestinationSheet.Cells(DestinationSheet.Rows.Count, "B").End(xlUp).Row
Dim VisibleCells As Range
On Error Resume Next 'next line errors if no visible cells so we turn error reporting off
Set VisibleCells = DestinationSheet.Range("A2", "A" & LastRow).SpecialCells(xlCellTypeVisible)
On Error Goto 0 'turn error reporting on or you won't see if other errors occur
If VisibleCells Is Nothing Then 'abort if no cells are visible in the filter
MsgBox "No cells to paste at"
Exit Sub
End If
Dim SourceRow As Long
SourceRow = 4 'start row in your source sheet
Dim Cell As Range
For Each Cell In VisibleCells.Cells 'loop through visible cells
Cell.Value = SourceSheet.Cells(SourceRow, "A").Value 'copy value
SourceRow = SourceRow + 1 'incerease source row
Next Cell
시트 이름 DestinationSheet
과 SourceSheet
함께 정의해야 합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다