I am trying to hide columns where the Value in the cells on row 9 is "", that cell being populated with a formula where the result is "". However I am getting the Compile Error Message 'Next without For'. Any clues?
I need to run this funtion from the starting column (N) to the last column ( dynamic).
Sub HideUnits() Dim rngData As Range, rngHide As Range Application. ScreenUpdating = False With Sheet1 .Rows(1).Insert .Range("B1").Value = "Temp" Set rngData = .Range("N1:N" & .Cells(Rows.Count, "N").End(xlUp).Row) rngData. AutoFilter field:=1, Criteria1:="*Units" Set rngHide = rngData.SpecialCells(xlCellTypeVisible) rngData.AutoFilter rngHide.EntireRow.Hidden = True .Rows(1).Delete End With Application.ScreenUpdating = True End Sub
As you might be able to tell I need to hide all the columns with a specific word in the heading. I'm pretty sure I'd need to loop this somehow, but I'm not good with VBA.
the support this board has given me as I learn VBA. I have three columns - Q, R, and S. I only need to see columns R and S if the cell values don't equal those in column Q or each other. So if I have cell values like the ones listed in the example below, then I don't need to see columns R and S.
I'm trying to hide columns based on information in another column. If that column contains "A" or "B", hide columns "U" through "W". If it contains "A", "B", "C", or "D", hide columns "V" through "W". Etc, etc., so on and so forth...
I've snipped the code I found earlier and modified it to (what I thought) was correct for my application, but it doesn't seem to do anything. (btw, should I get an error if it doesn't run correctly?)
Here is the code as modified:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "P:P" Then
If LCase(Target.Value) = "A" Or LCase(Target.Value) = "B" Then
Columns("U:W").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "A" Or LCase(Target.Value) = "B" Or LCase(Target.Value) = "C" Or LCase(Target.Value) = "D" Then
I have an elaborate spreadsheet that I have made for my company. I will give a little background how I have it set up: E6 contains a drop down menu of all products that we sell, and line items are populated based on the selection here. In columns N and O, I have a "Business Partner Costs" table that calculates a specific discount % based on the business partner.
Some of our products are sold to BPs with no discount. For these specific products, I am trying to get the BP Costs table to disappear, or hide.
Basically, I want something like: "=if(or(e6=ae2,e6=ae7,e6=ae12,e6=ae13,etc),hide columns N&O,show columns N&O)" in macro format.
I would like to write a macro that automatically hides columns of data based on the value of a cell (I2) with a picklist. Cell I2's picklist is monthly values (formatted as Jan-10 though Dec-10 but real values are 1/1/2010 through 12/1/2010). I have a range that contains work week end date values (1/8/2010 to 12/31/2010) in L6:BK6. I would like to have the macro hide columns that are less than date value chosen in I2.....
I'm referencing cells A25 and A26 as the range of columns I would like to hide in Sheet 2. I equated the cells in Sheet 1 to columns in Sheet 2. Unfortunately, the result was columns being hidden from column 1 to column x instead. I would greatly appreciate if anyone can kindly correct my macro. Also, may I ask how I can distribute the columns evenly after hiding/unhiding?
I have a worksheet that has >10 rows of data and over 150 columns. The values in the cells for individual row include NA, NE, D, A and S. Each row will have one or all of these values in one of the cells. Here is the question:
How do I hide columns containing 'NA' in the cell for a particular row, when only that row is selected by clicking on any cell in row 'A'? For example: If my row 3 cell values for column A, J, R, and X are 'NA' I want to hide the column containing 'NA' only and display everything else? And only when I click on row 3 column 'A'
I have an activeX combo-box that selects from different pieces of equipment that we supply. Based on that selection, I require ranges from the same page that the combo-box is on to either hide or unhide. Also, I require different tabs to become visible or hidden based on that same selection. So far so good - I have code that does this, and it appears to work without glitch.
Where the problem arises, is in one of the ranges that is unhidden when a particular piece of equipment is selected there is another combo-box that I would like to use (the number of said pieces of equipment to supply) to further hide/unhide additional ranges on the same page, and also hide/unhide certain tabs as well.
When I make a selection from combo-box 1, all works as planned, but when I change the state of combo-box 2, even with no associated coding referring to it, I cannot change combo-box 1 again without getting Error 1004 "Unable to get the Hidden property of the range class".
None of the sheets in the workbook are protected.
I would sincerely appreciate any help/code that could circumvent this error.
I have this model I created where I have two tabs. One tab is an input tab using validation and drop down menus and the other is a display tab. I simply want to hide certain QTRs based on the value of one of the drop down menu results. I tried writing the VBA code below but am a novice when it comes to code. Can somebody please help me fix the below code so that it works properly.
Public Sub hide() If Worksheets("input").Range("b14") = "Q1" Then Worksheets("Group P&L").Columns(c, d, e, h, i, j, m, n, o, r, s, t, w, x, y).Hidden = True ElseIf Worksheets("input").Range("b14") = "Q2" Then Worksheets("Group P&L").Columns(c, d, h, i, m, n, r, s, w, x).Hidden = True ElseIf Worksheets("input").Range("b14") = "Q3" Then Worksheets("Group P&L").Columns(c, h, m, r, w).Hidden = True ElseIf Worksheets("input").Range("b14") = "Q4" Then Worksheets("Group P&L").Columns.Hidden = False End If End Sub
I'm trying to hide all columns which have the word "hide" in row 6. I have done a similar thing whereby I hide all rows which have the word "hide" in column 3 using the following
Sub HURows() BeginRow = 9 EndRow = 40 ChkCol = 3 For RowCnt = BeginRow To EndRow If Cells(RowCnt, ChkCol).Value = "hide" Then Cells(RowCnt, ChkCol).EntireRow.Hidden = True Else Cells(RowCnt, ChkCol).EntireRow.Hidden = False End If Next RowCnt End Sub
Alas changing the number and every Col for Row and vice versa doesn't work!! Really I only need to search colums G to U inclusive. The code must also unhide colums if the values in the cells of row 6 change to anything other than "hide".
There's a sheet called "Main" and 38 other sheets that shows the data (these 38 sheets all have the exact same structure/layout). Let's say these 38 sheets are called "country1", "country2", .... "country38".
Based on user input in cell J10 in "Main", I want to show only the relevant columns in all of the 38 country sheets. Specifically,
If J10 in sheet "Main" = "Option 1", hide all columns in all 38 sheets except columns A to W.
If J10 in sheet "Main" = "Option 2", hide all columns in all 38 sheets except columns Y to AU.
If J10 in sheet "Main" = "Option 3", hide all columns in all 38 sheets except columns AW to BS.
If J10 in sheet "Main" = "Option 4", hide all columns in all 38 sheets except columns BV to CQ.
If J10 sheet "Main = "ShowAll", show all columns in all 38 sheets....
Cell J10 in "Main" will be a drop down bar with the 5 choices.....
I have a large table with an unknown number of columns and an unknown number of rows. The table contains no formulas and no errors - only text, numeric values and empty cells. The top row contains text (headers).
Column I contains below the header only zeros and/or 1s. However, a few entries in Column I might also be empty cells. Same is true for columns I+4 (i.e., M), I+8 (i.e., Q), I+12 (i.e., U), etc.
How could I hide ALL such columns (i.e., I, M, Q, U, etc.) with a VBA macro?
I was wondering if there was a simple function that will hide all the columns which have Zero value thoughout a pricing spreadsheet.
The different elements of the pricing have lead to 60+ columns, upto 75% may not contain a value or may display "false", it is making it very difficult to view and print. At present I am manually auto filterig to see if values are present in the column and then hiding the columns if they are blank (a real pain in the backside).
I have a some simple code that doesn't seem to want to work ALL the time. Granted, sometimes it works but not always. The first code is to hide a bunch of columns and the second is to display those again. I put in the If/Then to avoid trying to hide columns already hidden (I thgouht that had to be done - true). Anyone see any problems with this code. The error I get is:
"Run-time error '1004': Unable to set the hidden propoerty of Range class. I get it at
If wb.Worksheets("Growth").Columns("ap:iv").EntireColumn.Hidden = True Then wb.Worksheets("Growth").Columns("ap:iv").EntireColumn.Hidden = False 'Error is on this line End If..............
I'm running a macro with multiple statements for hiding columns, and it has been running well for years, now today i'm getting a error message in the macro while debugging that states "Unable to set the Hidden property of the Range class", and when I reset the macro, and try to manually hide the range, I get the error message "Cannot shift objects off sheet".
I am trying to hide columns in a range, "P8:ET1087" but it isn't working. After I autofilter a value, every row will be hidden except for the rows where the value is found. This is always 6 rows, won't be more or less.
The 6 cells in every column are the same and contain from 1 to 6: Text Text Date Number Text Date
What I am trying to do is to hide the column if all cells in that column are blank/empty after it's autofiltered. That for the 135 columns, from P to ET.
Iam an accoutant and have been given a task we have a workbook we use monthly that has about 50 columns, we have to go in and hide all the columns we do not need to print so I am wanting to create one that will hide the neccessary columsn print, unhide the columns and then hide the neccessary ones and print and so and so on.
I tried to do this by recording a macro and it sent me to visual basic and now says ithas all of these errors and i dont know how to fix them i need to do this porbabaly for about 20 different hiding and printing combinations. I am going to attach the errors i am getting when i try to debug in visual basic this is just for the first combination so i guess i need to know how to do debug for the rest of the combiantions. I am also hiding the entire column i dont know if i should be or not. I am attaching the file that i am doing the hising in as well. So like for the first i need to only keep column a,b,c (always unhidden) and then g for this time, print, unhide, then again column a,b,c active, then column u print and then unhide and on and on.
using VBA in excel. My questions is: I would like to make a listbox that has 1 column and shows all of the headers in my different worksheet columns, and I would like to hide the columns based on which ones are selected in the listbox, is this possible I am having trouble findings examples online.
I am attempting to creating a Macro in excel with an offset feature but I am having trouble getting it to work correctly. I will include what I have created thus far, but this is what I would like it to do. There are 2 columns, A and B which are header columns for rows 2 through 75. Columns C through G contain values which are referenced in formulas in the corresponding cells in columns H through the end of the sheet. Ideally after every day I would like to run the macro to hide the next 6 columns which are showing. So on day 1 I want to run the macro to hide columns H through M. On Day 2 I would like the macro to offset and hide the columns N through S and so on. Each day an additional 6 columns (which is the all the data for the previous day) need to be hidden so that the current day's data is showing and can be easily read alongside the headings which flow vertically down columns A and B. If you could please help me with the proper form of this macro I would greatly appreciate it. This is the current macro I have made, I would like to add an offset command in there but am unsure which line to tie it to:
Sub HidePreviousDay() ' ' HidePreviousDay Macro ' Hide the Previous 6 Columns (the entire last day) ' ' Keyboard Shortcut: Ctrl+Shift+H ' Columns("H:M").Select Range("H2").Activate Selection.EntireColumn.Hidden = True End Sub
I have a macro that works great to hide rows with zeros in a specific column on one sheet. It is below:
Sub Hide_Rows() Dim i As Integer ActiveSheet.Unprotect Password:="Yourpassword" Application. ScreenUpdating = False Application.Calculation = xlCalculationManual For i = 9 To 408 If Sheets("Tasks and times"). Range("H" & i).Value = 0 Then Rows(i & ":" & i).EntireRow.Hidden = True End If Next i Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True ActiveSheet.Protect Password:="Yourpassword" End Sub
My problem is that now I want to adapt it to also hide columns on another sheet in the same workbook (named OBS). This is because in the first sheet rows 9 through 408 are used for data but that range is divided into 25 sets of 16 rows. Each set corresponds to a column on the other sheet starting at column C. I would like the corresponding column to hide when the first row of each set (i.e. rows 9, 25, 41, etc.) are hidden.
I am using an area of 43 Rows by ~ 150 Columns to display the results of an advancedfilter process. I have a trigger on row 44 for each column (which is either 1 or 0, depending on if any of the rows in the column were filled with data. If any column is completely empty I would like to hide it. I am getting an error if the majority of the ~ 150 columns are empty and should be hidden. Does anyone know if there is a maximum number of columns that can be hidden each time a macro is run?
My piece of code to accomplish this is as follows:
For i = 4 To 150 If Worksheets("RegMatrix"). Cells(44, i) = 1 Then Worksheets("RegMatrix").Columns(i).AutoFit Else Worksheets("RegMatrix").Columns(i).ColumnWidth = 1 Worksheets("RegMatrix").Columns(i).Hidden = True On Error Resume Next End If Next
Right now, once i gets to about 100 the rest of the columns are not hidden.