Solved

VBA to hide hide specific columns on more than one worksheet

Posted on 2014-03-05
10
168 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
  • 5
  • 3
  • 2
10 Comments
 
LVL 49

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 49

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
 
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 49

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Outline Suppose you have some simple text based data in Excel that you would like to display as a PowerPoint presentation. Of course it would be possible to write some fairly complex VBA code that created a new slide for each line of the Excel data…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

914 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now