VBA Code works in one workbook but not another

kbianco

New Member
Joined
Aug 9, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I am working with a VBA code to help clean up some formatting within my excel workbooks. I am using the below code in one workbook, but when i try to apply it to another (larger) workbook I receive an error. The two workbooks are exactly the same, except one has more sheets than the other (contents of each sheet are more or less the same).

The error message I am getting is Run-time error 1004: Unable to set the Hidden property of the Range class. It seems like it is pointing to the Hidden Row component of the code.

Sub Row_Column_workbook()
Dim ws As Worksheet
For Each ws In Worksheets
With ws
.Columns("M:S").ColumnWidth = 0.25
.Rows("46:71").RowHeight = 0.5
.Columns("T:XFD").Hidden = True
.Rows("73:1048576").Hidden = True
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayHeadings = False
End With
Next ws
End Sub

Any insight is greatly appreciated.

Thank you,
Kayla
 
Hi again - thank you for the input. In looking at this again, I am still getting the same error BUT when I select debug, then continue run the code works as expected. Have you encountered this type of behavior before/

Thanks!
Kayla
@kbianco , You could always throw in an On Error Resume Next statement if the code seems to run properly after debug/continue.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top