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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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