Hi, I have been trying for several days and using many different codes to try to get this to work i am currently using the below code
When i use this code nothing happens but i dont get an error message either to help me figure out whats not working i am a complete newbie to VBA so any help would be appreciated. I am currently trying to get the code to work for one sheet only but i would need some help adapting the code for my other sheets in the workbook if someone can at least help either the code for one sheet / for all the sheets anything would help
My workbook
12 Sheets for each month
Completed sheet
Summary sheet
Master sheet
What i need
On each of the sheets for the month (Example below is for july sheet only as i havent been able to get that to work to even look at looping through all months ) but i would ideally like one code that loops through each sheet for the month only rather than having to individually complete each sheet
When there is a change for example : In "July" Column J starting from J5 from a drop down list if Completed is selected or cell value is equal to completed then copy entire row (my data starts in C column so copying from Column C the "Completed" sheet and paste with formula starting from C5 but paste below last row of data so the previous data is not overwritten. (I would like this for all the monthly sheets so when there is a change it automatically transfers if possible)
Once the row is copied i would like the row to be deleted from the original July sheet so that there is no blank rows in my data on my July sheet
Sub Archive()
Dim lastRow As Long
Dim i As Long
' Set the worksheet variables
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Set sourceSheet = ThisWorkbook.Sheets("July ")
Set targetSheet = ThisWorkbook.Sheets("completed")
' Find the last row of data in Column J on the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "J").End(xlUp).Row
' Loop through each row in Column J
For i = 5 To lastRow
' Check if the cell value is "completed"
If sourceSheet.Cells(i, "J").Value = "completed" Then
' Copy the entire row
sourceSheet.Rows(i).Copy
' Find the last row of data on the target sheet
Dim targetLastRow As Long
targetLastRow = targetSheet.Cells(targetSheet.Rows.Count, "C").End(xlUp).Row
' Paste special the row on the target sheet
targetSheet.Cells(targetLastRow + 1, "C").PasteSpecial Paste:=xlPasteValues
End If
Next i
' Clear the clipboard
Application.CutCopyMode = False
End Sub
When i use this code nothing happens but i dont get an error message either to help me figure out whats not working i am a complete newbie to VBA so any help would be appreciated. I am currently trying to get the code to work for one sheet only but i would need some help adapting the code for my other sheets in the workbook if someone can at least help either the code for one sheet / for all the sheets anything would help
My workbook
12 Sheets for each month
Completed sheet
Summary sheet
Master sheet
What i need
On each of the sheets for the month (Example below is for july sheet only as i havent been able to get that to work to even look at looping through all months ) but i would ideally like one code that loops through each sheet for the month only rather than having to individually complete each sheet
When there is a change for example : In "July" Column J starting from J5 from a drop down list if Completed is selected or cell value is equal to completed then copy entire row (my data starts in C column so copying from Column C the "Completed" sheet and paste with formula starting from C5 but paste below last row of data so the previous data is not overwritten. (I would like this for all the monthly sheets so when there is a change it automatically transfers if possible)
Once the row is copied i would like the row to be deleted from the original July sheet so that there is no blank rows in my data on my July sheet
Sub Archive()
Dim lastRow As Long
Dim i As Long
' Set the worksheet variables
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Set sourceSheet = ThisWorkbook.Sheets("July ")
Set targetSheet = ThisWorkbook.Sheets("completed")
' Find the last row of data in Column J on the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "J").End(xlUp).Row
' Loop through each row in Column J
For i = 5 To lastRow
' Check if the cell value is "completed"
If sourceSheet.Cells(i, "J").Value = "completed" Then
' Copy the entire row
sourceSheet.Rows(i).Copy
' Find the last row of data on the target sheet
Dim targetLastRow As Long
targetLastRow = targetSheet.Cells(targetSheet.Rows.Count, "C").End(xlUp).Row
' Paste special the row on the target sheet
targetSheet.Cells(targetLastRow + 1, "C").PasteSpecial Paste:=xlPasteValues
End If
Next i
' Clear the clipboard
Application.CutCopyMode = False
End Sub