Solved

VBA to hide hide specific columns on more than one worksheet

Posted on 2014-03-05
10
172 Views
Last Modified: 2014-03-22
I am currently using this code below to hide columns H and M on the Cartoworkflow sheet. I would also like to hide column G on a worksheet called "NEW_Procedures" located in the same workbook. I tried to just add a line in the code below, but am getting an error message.

Private Sub Workbook_Open()
    Sheets("Cartoworkflow").Columns("h:h").ColumnWidth = 0
    Sheets("Cartoworkflow").Columns("m:m").ColumnWidth = 0
    If WorksheetFunction.CountA(Sheet8.Cells) = 0 Then
        InitCopyRow
    End If
End Sub

Please advise...thanks!
Andrea
0
Comment
Question by:Andreamary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39906102
Hi,

pls try

    Sheets("Cartoworkflow").Range("h:h,m:m").ColumnWidth = 0
    Sheets("NEW_Procedures").Range("g:g").ColumnWidth = 0

Open in new window


if you get an error pls verify the Sheets names for blank spaces or other typing errrors.

Regards
0
 

Author Comment

by:Andreamary
ID: 39906105
Still receiving the error, and I've checked the spreadsheet names as recommended...
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 39906116
Could you send a dummy example

EDIT

What is the text of the error and where does the code stop?

Regards
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:5teveo
ID: 39906503
Try

Sheets("Cartoworkflow").Select
Columns("G:G").Select
Selection.EntireColumn.Hidden = True
0
 

Author Comment

by:Andreamary
ID: 39906706
Rgonzo, since you answered first I'll respond to your questions before trying other solutions offered..

I get a run-time error 1004
Unable to set the ColumnWidth property of the Range class

When I click on debug the following line is highlighed in yellow:

Sheets("NEW_Procedures").Range("g:g").ColumnWidth = 0

Due to the confidentiality and complexity of the workbook I haven't had the time to create a dummy yet. I'm hoping to find someone that can offer a solution without going that route, but understand that may not be possible, in which case I'll follow up...

Andrea
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 39906973
Hi,

Do you have some buttons or checkboxes on the G column?

Regards
0
 

Author Comment

by:Andreamary
ID: 39907282
No, column G is empty...
0
 
LVL 8

Expert Comment

by:5teveo
ID: 39907331
If you want 1 line command...

Sheets("NEW_Procedures").Columns("G:G").Hidden = True
0
 

Author Comment

by:Andreamary
ID: 39922101
I will create a dummy spreadsheet and upload it...

Andrea
0
 

Author Closing Comment

by:Andreamary
ID: 39947437
Sorry to have taken so long to close this question. The spreadsheet was undergoing some substantive structural changes and I've been waiting on input. Upon completion of the changes, I tried this solution and it worked perfectly. Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question