Copy/Paste from one worksheet to another only values to last cell

Konrado

New Member
Joined
Jun 17, 2014
Messages
34
Hi, I have problem with my macro code. I want to copy only values from Worksheet A (in which in cells are formulas) to Worksheet B to next empty cell. Any help will be appreciated.

My code below, which doesn't work:


Sub CrossCheck()

Dim Lastrow, i As Long

Lastrow = Range("B" & Rows.Count).End(xlUp).Row
LastRow1 = Sheets("CrossCheck").Range("A" & Rows.Count).End(xlUp).Row

Sheets("Input").Activate

For i = 5 To Lastrow

If Range("B" & i).Value = "ABC" And Range("D" & i).Value = "X" Then
Range("C" & i).Copy Sheets("Sheet2").Cells(LastRow1, "A").PasteSpecial, xlPasteValues

End If

Next i

End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Code:
Sub CrossCheck()

    Dim endRow As Long
    Dim endRowDest As Long
    
    Dim inp As Worksheet
    Dim outp As Worksheet
    
    Set inp = Sheets("Input")
    Set outp = Sheets("CrossCheck")
    
    endRow = inp.Cells(Rows.Count, "B").End(xlUp).Row
    endRowDest = outp.Cells(Rows.Count, "A").End(xlUp).Row
    
    With inp
        For x = 5 To endRow
            If .Cells(x, 2).Value = "ABC" And .Cells(x, 4).Value = "X" Then
                outp.Cells(endRowDest, 1).Value = .Cells(x, 3).Value
                endRowDest = endRowDest + 1
            End If
        
    End With
End Sub

Why do you have Sheet2 and CrossCheck? You are using the value from CrossCheck's last row, but pasting into Sheet2?
 
Upvote 0
Hi, I made a mistake by accident, but of course in my code I had right value. I suppose, you missed "next x" in loop, however, it works perfectly. Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top