Hey,
What I'm trying to acheive is following:
In the activesheet I want to copy a given row if the K column is non-empty and column L is empty. The row is copied into first empty row in another worksheet (C:\Users\bruger\Desktop\Excel\nytark.xlsx). The sheet, from which the data is copied, has a header in first row, and the copying should therefore start from second row. Thank you in advance for your help and effort!
The code I have so far, found mostly at the forum and web, is following:
![]()
Sub CopyRows() Dim wks As Worksheet Dim wbkPasteTo As Workbook Dim rngPasteTo As Range Dim rngFound As Range Dim rngFirst As Range Dim rngFoundAll As Range Dim rngToSearch As Range Set wks = Sheets("Sheet1") Set rngToSearch = wks.Columns("K") Set rngFound = rngToSearch.Find(What:="*", LookAt:=xlWhole) If rngFound Is Nothing Then MsgBox "Sorry Nothing to Move" ElseIf rngFound Is Not Nothing And rngFound.Offset(0, 1) = "" Then 'if this line is reduced to "Else" the code works, _ but without the desired condition Set rngFoundAll = rngFound.EntireRow Set rngFirst = rngFound Do Set rngFoundAll = Union(rngFoundAll, rngFound.EntireRow) Set rngFound = rngToSearch.FindNext(rngFound) Loop Until rngFound.Address = rngFirst.Address On Error GoTo OpenBook Set wbkPasteTo = Workbooks("nytark.xlsx") On Error GoTo 0 Set rngPasteTo = wbkPasteTo.Sheets("Ark1").Cells(Rows.Count, _ "A").End(xlUp).Offset(1, 0) rngFoundAll.Copy rngPasteTo End If Exit Sub OpenBook: Workbooks.Open ("C:\Users\bruger\Desktop\Excel\nytark.xlsx") Resume End Sub
Bookmarks