Страницы: 1
RSS
Копирование в VBA только значения ячеек
 
Подскажите как исправить код чтобы копировались только значения ячеек:
Код
Sub COPY_TOLKO_ZAGOTOVITELNU()
Dim iLastRow As Long, i As Long, LastRow As Long
iLastRow = Cells(Rows.Count, 1).End(xlUp).Row
    With Sheets("DATA000")
        LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
        'Cells(LastRow + 1, "D").ClearContents
        'Range("D2:D10").ClearContents
        .Range(.Cells(2, "D"), .Cells(LastRow + 1, "D")).ClearContents
        .Range(.Cells(2, "J"), .Cells(LastRow + 1, "J")).ClearContents
        .Range(.Cells(2, "P"), .Cells(LastRow + 1, "P")).ClearContents
        LastRow = 1
        For i = 2 To iLastRow
                If InStr(1, Cells(i, "O"), "zag", vbTextCompare) <> 0 Then
                    Cells(i, "H").COPY .Cells(LastRow + 1, "D")
                    Cells(i, "K").COPY .Cells(LastRow + 1, "J")
                    Cells(i, "I").COPY .Cells(LastRow + 1, "P")
                    LastRow = LastRow + 1
                End If
        Next
    End With
End Sub
 
Cмотрите в сторону Pastespecial xlValues
Вариант в следующем сообщении лучше.
Изменено: Wiss - 17.10.2019 15:49:48
Я не волшебник, я только учусь.
 
Код
.Cells(LastRow + 1, "D").Value = Cells(i, "H").Value
 
Код
Sub COPY_TOLKO_ZAGOTOVITELNU()
    Dim iLastRow As Long, i As Long, LastRow As Long
    iLastRow = Cells(Rows.Count, 1).End(xlUp).Row
    With Sheets("DATA000")
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Range("D2:D" & LastRow).ClearContents
        .Range("J2:J" & LastRow).ClearContents
        .Range("P2:P" & LastRow).ClearContents
        LastRow = 2
        For i = 2 To iLastRow
            If Cells(i, "O") Like "*zag*" Then
                .Cells(LastRow, "D") = Cells(i, "H")
                .Cells(LastRow, "J") = Cells(i, "K")
                .Cells(LastRow, "P") = Cells(i, "I")
                LastRow = LastRow + 1
            End If
        Next
    End With
End Sub
Изменено: skais675 - 17.10.2019 15:56:01
 
МатросНаЗебре Большое спасибо
 
skais675,
Код
If UCase$(Cells(i, "O")) Like "*ZAG*" Then
, потому что InStr(1, Cells(i, "O"), "zag", vbTextCompare)
Во всех делах очень полезно периодически ставить знак вопроса к тому, что вы с давних пор считали не требующим доказательств (Бертран Рассел) ►Благодарности сюда◄
Страницы: 1
Наверх