Solved

VBA to hide hide specific columns on more than one worksheet

Posted on 2014-03-05
10
170 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 50

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 50

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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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 50

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
With the internet and the ease of information transference, many professional jobs can be done anywhere today.  Why should it make a difference whether an x-ray is read in India or the United States as long as the radiologist is qualified?   Outso…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

856 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