I have tried to write code to autofit only those cols containing ####
However, these cols are not being autofitted
It would be appreciated if you someone could kindly amend my code
Sub AutofitColumnsWithHashes()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
' Set the worksheet variable to the "Sales Data" sheet
Set ws = ThisWorkbook.Sheets("Sales Data")
' Loop through each column in the worksheet
For Each rng In ws.UsedRange.Columns
' Check if any cell in the column displays "#####"
For Each cell In rng.Cells
If cell.Value = "#####" Then
' Autofit the column width
rng.EntireColumn.AutoFit
Exit For
End If
Next cell
Next rng
End Sub
Bookmarks