nrodrigues23
New Member
- Joined
- Apr 9, 2019
- Messages
- 14
I have written a code to automatically update the width of columns based on what is in a particular range of cells. See the code below.
Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Cells.Range("A10:DC49").Columns.AutoFit
For i = 1 To ActiveSheet.Range("A:DC").Columns.Count
Columns(i).ColumnWidth = Columns(i).ColumnWidth - 0.35
Next i
Application.ScreenUpdating = True
End Sub
Now that I have gotten this code to work I would like to set the same thing up in other tabs. I keep getting a Run-time error every time I try to copy this to another tab in my workbook. Do I have to assign the code to something other than "activesheet" and if so, what does the code look like to do that?
Thanks.
Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Cells.Range("A10:DC49").Columns.AutoFit
For i = 1 To ActiveSheet.Range("A:DC").Columns.Count
Columns(i).ColumnWidth = Columns(i).ColumnWidth - 0.35
Next i
Application.ScreenUpdating = True
End Sub
Now that I have gotten this code to work I would like to set the same thing up in other tabs. I keep getting a Run-time error every time I try to copy this to another tab in my workbook. Do I have to assign the code to something other than "activesheet" and if so, what does the code look like to do that?
Thanks.