facedown12
New Member
- Joined
- Jun 4, 2015
- Messages
- 2
Hi All,
I'm trying to create a macro to will select the entire row if it meets a condition as "Completed" in column b and paste it as values within the same row that it is currently in. I got it to work up to the copy stage, but having trouble pasting it, as my file is also protected with locked cells. I used this code from someone else online, but trying to modify it.
The reason I want this code to work, is because I don't want my formula in column b to keep changing once the condition has been met
Sub Copy_Paste()
Dim LastRowS As Long
Dim LastRowT As Long
'Assign variables for Current Sheet, Target Sheet and search string
cs = ActiveSheet.Name
Var1 = "Completed"
'Loop through all worksheets except listed
For Each wks In ActiveWorkbook.Worksheets
'Do this for all sheets except these
Select Case wks.Name
Case ts, "HG Wip"
'do nothing with the above worksheets
Case Else
'With worksheets not listed, do the following...
With wks
Sheets(wks.Name).Activate
LastRowS = Cells(Rows.Count, 4).End(xlUp).Row
Set Source = Range("B2:B" & LastRowS)
For Each c In Source
If c.Value = Var1 Then
'Copy Rows that meet Criteria
c.EntireRow.Copy
c.Enttirerow.PasteSpecial Paste:=Values
End If
Next c
End With
End Select
Next wks
Sheets(cs).Activate 'Return to Current Worksheet when done
'Clear memory
Set Source = Nothing
End Sub
I'm trying to create a macro to will select the entire row if it meets a condition as "Completed" in column b and paste it as values within the same row that it is currently in. I got it to work up to the copy stage, but having trouble pasting it, as my file is also protected with locked cells. I used this code from someone else online, but trying to modify it.
The reason I want this code to work, is because I don't want my formula in column b to keep changing once the condition has been met
Sub Copy_Paste()
Dim LastRowS As Long
Dim LastRowT As Long
'Assign variables for Current Sheet, Target Sheet and search string
cs = ActiveSheet.Name
Var1 = "Completed"
'Loop through all worksheets except listed
For Each wks In ActiveWorkbook.Worksheets
'Do this for all sheets except these
Select Case wks.Name
Case ts, "HG Wip"
'do nothing with the above worksheets
Case Else
'With worksheets not listed, do the following...
With wks
Sheets(wks.Name).Activate
LastRowS = Cells(Rows.Count, 4).End(xlUp).Row
Set Source = Range("B2:B" & LastRowS)
For Each c In Source
If c.Value = Var1 Then
'Copy Rows that meet Criteria
c.EntireRow.Copy
c.Enttirerow.PasteSpecial Paste:=Values
End If
Next c
End With
End Select
Next wks
Sheets(cs).Activate 'Return to Current Worksheet when done
'Clear memory
Set Source = Nothing
End Sub