Hello
I'm moving completed tasks from one sheet to another and want to be able to move a task back into my worklist sheet.
I have a vba code in Excel for cutting and pasting rows from one sheet to another based on cell value="completed". Now I want to be able to reverse fromthe completed worksheet, by cutting and pasting rows not equal to the specific text string.
I thought, that I could just change "=" to "<>" in my code line [If sourceSheet.Cells(i, "C").Value = "Completed" Then], but then I get the error mesage, that my clipboard is used by another application. I have a list of choices (not startet; ongoing; delayed; completed), so I can't just pick another specific text string.
My code:
Sub MoveRowsToCompleted()
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim lastRow As Long
Dim i As Long
' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("Worklist")
Set targetSheet = ThisWorkbook.Worksheets("Completed")
' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "B").End(xlUp).Row
' Loop through each row in the source sheet
For i = 3 To lastRow
' Check if cell in column C contains "Completed"
If sourceSheet.Cells(i, "C").Value = "Completed" Then
' Copy the entire row to the target sheet
sourceSheet.Rows(i).Copy Destination:=targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Offset(1)
' Delete the row from the source sheet
sourceSheet.Rows(i).Delete
' Decrement the loop counter as the rows are shifting up
i = i - 1
' Update the last row value
lastRow = lastRow - 1
End If
Next i
End Sub
Sub MoveRowsToWorklist()
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim lastRow As Long
Dim i As Long
' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("Completed")
Set targetSheet = ThisWorkbook.Worksheets("Worklist")
' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "B").End(xlUp).Row
' Loop through each row in the source sheet
For i = 3 To lastRow
' Check if cell in column C contains "Completed"
If sourceSheet.Cells(i, "C").Value <> "Completed" Then
' Copy the entire row to the target sheet
sourceSheet.Rows(i).Copy Destination:=targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Offset(1)
' Delete the row from the source sheet
sourceSheet.Rows(i).Delete
' Decrement the loop counter as the rows are shifting up
i = i - 1
' Update the last row value
lastRow = lastRow - 1
End If
Next i
End Sub
Can someone help me solve the problem?
Thanks
MLAN1604
I'm moving completed tasks from one sheet to another and want to be able to move a task back into my worklist sheet.
I have a vba code in Excel for cutting and pasting rows from one sheet to another based on cell value="completed". Now I want to be able to reverse fromthe completed worksheet, by cutting and pasting rows not equal to the specific text string.
I thought, that I could just change "=" to "<>" in my code line [If sourceSheet.Cells(i, "C").Value = "Completed" Then], but then I get the error mesage, that my clipboard is used by another application. I have a list of choices (not startet; ongoing; delayed; completed), so I can't just pick another specific text string.
My code:
Sub MoveRowsToCompleted()
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim lastRow As Long
Dim i As Long
' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("Worklist")
Set targetSheet = ThisWorkbook.Worksheets("Completed")
' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "B").End(xlUp).Row
' Loop through each row in the source sheet
For i = 3 To lastRow
' Check if cell in column C contains "Completed"
If sourceSheet.Cells(i, "C").Value = "Completed" Then
' Copy the entire row to the target sheet
sourceSheet.Rows(i).Copy Destination:=targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Offset(1)
' Delete the row from the source sheet
sourceSheet.Rows(i).Delete
' Decrement the loop counter as the rows are shifting up
i = i - 1
' Update the last row value
lastRow = lastRow - 1
End If
Next i
End Sub
Sub MoveRowsToWorklist()
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim lastRow As Long
Dim i As Long
' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("Completed")
Set targetSheet = ThisWorkbook.Worksheets("Worklist")
' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "B").End(xlUp).Row
' Loop through each row in the source sheet
For i = 3 To lastRow
' Check if cell in column C contains "Completed"
If sourceSheet.Cells(i, "C").Value <> "Completed" Then
' Copy the entire row to the target sheet
sourceSheet.Rows(i).Copy Destination:=targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Offset(1)
' Delete the row from the source sheet
sourceSheet.Rows(i).Delete
' Decrement the loop counter as the rows are shifting up
i = i - 1
' Update the last row value
lastRow = lastRow - 1
End If
Next i
End Sub
Can someone help me solve the problem?
Thanks
MLAN1604