Excel crash - bug macro?

  • Thread starter Thread starter al007
  • Start date Start date
A

al007

Is there any bug in the macro below - as i'm getting an error report
when i close my excel.

Thxs



Sub columnWidthSelection5()


Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Columns.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Columns
End If
For R = Rng.Columns.Count To 1 Step -1
If
Application.WorksheetFunction.CountA(Rng.Columns(R).EntireColumn) = 0
Then
Rng.Columns(R).EntireColumn.Columnwidth = 0.5
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub
 
Hi Al007,
If
Application.WorksheetFunction.CountA(Rng.Columns(R).EntireColumn) = 0
Then

Should all be on one line:

If Application.WorksheetFunction.CountA(Rng.Columns(R). _
EntireColumn) = 0
Then

If this is not your problem, then post the relevant error message and
indicate the code line that is highlighted on error.
 
Hi Al007,

Attempting to beat line wrap, the indicated code snippet should be one
line:

If Application.WorksheetFunction. _
CountA(Rng.Columns(R).EntireColumn) = 0 Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top