Hello, I am attempting to loop through all of my worksheets and if the worksheet begins with "Labor BOE" I would like to copy/paste everything as values (there are formulas all over the sheet that I want to paste as values). Unfortunately, all of my attempts only work on the current "Labor BOE" worksheet that is open and doesn't loop through the others to paste values. Any thoughts?
Last row determined by column T.
Last column = Column U (aka Column 21)
Attempt #1: works on active sheet, doesn't loop through all sheets
Attempt 2:
Last row determined by column T.
Last column = Column U (aka Column 21)
Attempt #1: works on active sheet, doesn't loop through all sheets
Code:
Sub Paste_Values_2()
'STEP 1: Define variables
Dim Sh As Worksheet
Dim A As Long
Dim Dest_End_Row As Long
For A = 1 To Sheets.Count
If Left(Sheets(A).Name, 9) = "Labor BOE" Then
Dest_End_Row = Sheets(A).Cells(Rows.Count, "T").End(xlUp).Row
With Sheets(A).Range(Cells(1, 1), Cells(Dest_End_Row, 21))
.Value = .Value
End With
End If
Next
End Sub
Attempt 2:
Code:
Sub Paste_Values_2()
'STEP 1: Define variables
Dim Sh As Worksheet
Dim A As Long
Dim Dest_End_Row As Long
For Each Sh In ActiveWorkbook.Worksheets
If Left(Sh.Name, 9) = "Labor BOE" Then
Dest_End_Row = Sh.Cells(Rows.Count, "T").End(xlUp).Row
With Range(Cells(1, 1), Cells(Dest_End_Row, 21))
.Value = .Value
End With
End If
Next Sh
End Sub