copy selected cells from one row and paste into last row +1 in another worksheet

bryanrobson

New Member
Joined
Aug 19, 2022
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi. I have the code below. I have selected data in cells A, B, C, F, G and H. UI have copied that row and I want to paste that into another worksheet ws2 / Combined for Lookup into the next row available after the last row.
I dont want to use some form of a loop. Is there a one liner of code I can do that with as I dont want to use a loop to just copy one line and paste straight away into another sheet.

Many thanks


Set WsF = Application.WorksheetFunction
Set ws1 = ThisWorkbook.Sheets("events log")
Set ws2 = ThisWorkbook.Sheets("Combined for Lookup")
For Rw = 2 To 9999
On Error Resume Next
ws1.Cells(Rw, "I") = WsF.VLookup(ws1.Cells(Rw, "B"), ws2.Range("B2:G9999"), 6, False)

If ws1.Cells(Rw, "I") = "n/a" Or _
ws1.Cells(Rw, "I") = "" Then

ws1.Cells(Rw, 1).EntireRow.Font.Bold = True
ws1.Cells(Rw, 1).EntireRow.Font.Color = Black

shtName = "A" & Rw & "," & "B" & Rw & "," & "C" & Rw & "," & "F" & Rw & "," & "G" & Rw & "," & "H" & Rw
Range(shtName).Select
Selection.Copy



End If

Next Rw
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe helps you...
VBA Code:
Sub Transfer()
    
    Lrow2 = Sheets("Combined for Lookup").Cells(Rows.Count, 1).End(xlUp).Row + 1
    Lrow1 = Sheets("events log").Cells(Rows.Count, 1).End(xlUp).Row
    Lin = Lrow2
    
    For i = 2 To Lrow1
        If Sheets("events log").Cells(i, 9).Value = "n/a" Or Sheets("events log").Cells(i, 9).Value = "" Then
            Sheets("Combined for Lookup").Cells(Lin, 1) = Sheets("events log").Cells(i, 1)
            Sheets("Combined for Lookup").Cells(Lin, 2) = Sheets("events log").Cells(i, 2)
            Sheets("Combined for Lookup").Cells(Lin, 3) = Sheets("events log").Cells(i, 3)
            Sheets("Combined for Lookup").Cells(Lin, 4) = Sheets("events log").Cells(i, 4)
            Sheets("Combined for Lookup").Cells(Lin, 5) = Sheets("events log").Cells(i, 5)
            Sheets("Combined for Lookup").Cells(Lin, 6) = Sheets("events log").Cells(i, 6)
            Sheets("Combined for Lookup").Cells(Lin, 7) = Sheets("events log").Cells(i, 7)
            Sheets("Combined for Lookup").Cells(Lin, 8) = Sheets("events log").Cells(i, 8)
            Sheets("Combined for Lookup").Cells(Lin, 9) = Sheets("events log").Cells(i, 9)
            
            Lin = Lin + 1
            
        End If
        
    Next
    
    
End Sub
 
Upvote 0
Solution
Maybe helps you...
VBA Code:
Sub Transfer()
   
    Lrow2 = Sheets("Combined for Lookup").Cells(Rows.Count, 1).End(xlUp).Row + 1
    Lrow1 = Sheets("events log").Cells(Rows.Count, 1).End(xlUp).Row
    Lin = Lrow2
   
    For i = 2 To Lrow1
        If Sheets("events log").Cells(i, 9).Value = "n/a" Or Sheets("events log").Cells(i, 9).Value = "" Then
            Sheets("Combined for Lookup").Cells(Lin, 1) = Sheets("events log").Cells(i, 1)
            Sheets("Combined for Lookup").Cells(Lin, 2) = Sheets("events log").Cells(i, 2)
            Sheets("Combined for Lookup").Cells(Lin, 3) = Sheets("events log").Cells(i, 3)
            Sheets("Combined for Lookup").Cells(Lin, 4) = Sheets("events log").Cells(i, 4)
            Sheets("Combined for Lookup").Cells(Lin, 5) = Sheets("events log").Cells(i, 5)
            Sheets("Combined for Lookup").Cells(Lin, 6) = Sheets("events log").Cells(i, 6)
            Sheets("Combined for Lookup").Cells(Lin, 7) = Sheets("events log").Cells(i, 7)
            Sheets("Combined for Lookup").Cells(Lin, 8) = Sheets("events log").Cells(i, 8)
            Sheets("Combined for Lookup").Cells(Lin, 9) = Sheets("events log").Cells(i, 9)
           
            Lin = Lin + 1
           
        End If
       
    Next
   
   
End Sub
thanks a lot. much appreciated
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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