I tried the below, but it is not doing exactly what I need it to. Instead of unprotecting the sheet and clearing the contents of grey cells (191, 191, 191) I'd like to change the approach and clear the contents of unprotected cells.
As the file is then "saving as" cell value "B5", any new sheets are created on the newly named sheet. I'd like the sheet to still save as cell value "B5" to the specified path, but then close that workbook and open up the original workbook again.
I cannot seem to make the flow correctly, and have had various run time errors as well.
Sub Button6_Click()
Dim FileName As String
Dim CellValue As String
' Get the value from cell A1 to use as the file name
CellValue = ThisWorkbook.Sheets("Adjustment Sheet").Range("B5").Value
' Construct the full file path and name
' You can change "Sheet1" to your actual sheet name
' And "C:\Your\Path\" to your desired folder path
FileName = "S:\Operations\S2\RP500e Refurb Cost Sheet\" & CellValue & ".xls"
' Save the file with the new name
ThisWorkbook.SaveAs FileName
End Sub
Sub UnprotectSheet()
'Unprotect a worksheet without a password
Sheets("Adjustment Sheet").Unprotect
Range("A1:AA118").Select
For Each Cell In Selection
If Cell.Interior.Color = RGB(191, 191, 191) Then
Cell.ClearContents
End If
Next
End Sub
For Each Cell In Sheets("Adjustment Sheet").Range("A1:AA118") : If Not Cell.Locked Then Cell.ClearContents : Next. No need to Unprotect sheet first.ThisWorkbook.SaveCopyAs FileNameSee learn.microsoft.com/en-us/office/vba/api/…