Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have the following macro that will hide columns perfectly. But i would also li

ID: 3562510 • Letter: I

Question

I have the following macro that will hide columns perfectly. But i would also like this macro or another macro to autosize the columns so that the numbers can be seen instead of the xxxxxx value in the row and column. Can anybody help me on this matter?

Sub FilterCenterColumns()

Dim wsInput As Worksheet
Set wsInput = Sheet3
wsInput.Select
ActiveSheet.Unprotect Password:="cfs101"
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

Dim MyRange As Range
Dim c As Range

Set MyRange = ActiveSheet.Range("F3:AO3")

For Each c In MyRange
If c.Value = "x" Then

Columns(c.Column).Hidden = True
End If
Next

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
ActiveSheet.Protect Password:="cfs101"
End Sub!

Explanation / Answer

Addition in bold

Sub FilterCenterColumns()

Dim wsInput As Worksheet
Set wsInput = Sheet3
wsInput.Select
ActiveSheet.Unprotect Password:="cfs101"
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

Dim MyRange As Range
Dim c As Range

Set MyRange = ActiveSheet.Range("F3:AO3")
For Each c In MyRange
If c.Value = "x" Then
Columns(c.Column).Hidden = True
End If

If Columns(c.Column).Hidden = False Then
   
    Columns(c.Column).AutoFit
End If

Next

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
ActiveSheet.Protect Password:="cfs101"
End Sub