I am trying to edit the code below to hide the (blank) values in the field options list. I think because I am using a data model, I am getting a little tripped up with the syntax. I am getting the error message, "Unable to get the PivotItems property of the PivotField class"
Sub hi()
With ActiveSheet.PivotTables("PivotTable3").PivotFields("[Range 2].[Goal].[Goal]")
.PivotItems("(blank)").visible = False
End With
End Sub
I think you may be able to solve for this by selecting the Pivot Table entirely and attempting to find all of the blanks from the data that is being pulled into the Pivot.
Select a column in your worksheet that contains blank rows.
Press Ctrl+F on the keyboard to open the Find & Replace box.
Select theFind tab and click on Options to open the advanced menu. Don’t input anything in the Find what box.
Check the box beside Match entire cell contents.
Select Sheet from the drop-down menu of Within.
Select Values from the drop-down menu of Look in.
Click on Find All button to get all the blank cells in the selected range.
Select all these rows by Ctrl+A.
Close the Find box.
Delete the rows by clicking on the right button, and selecting the Delete option.
I hope this helps! You can view the whole article that has screenshots on how to do this here.
I could suggest adding an slicer where the default view could be an unselected option for the blanks values.
Dim slcCache as SlicerCache '' Object to manipulate the slicer
Set slcCache = ActiveWorkbook.SlicerCaches("SlicerName") '' Assign object
With slcCache
.ClearManualFilter
.SlicerItems("(blank)").Selected = False '' False value to unselect
'' I do not remember if this is the actual name for an empty value,
'' but you could find it or replace it by the index that should be 1
End with
Related
I have checkboxes set for each line. I would like that if the checkbox is selected after running the macro, values from one column were automatically copied to the clipboard. How to do it? So far I have written something like this.
Sub CopyCheckedRowsToClipboard()
Dim ctCB As CheckBox
'Process all checkboxes in the ActiveSheet
For Each ctCB In ActiveSheet.CheckBoxes
'If the checkbox is checked, select the row, then copy
If ctCB = 1 Then
ctCB.TopLeftCell.EntireRow.Select
ctCB.Copy
End If
Next ctCB
End Sub
What am I doing wrong?
The table I have:
My table
The effect I want to get:
Effect macro
I have a pivot table with a slicer. The slicer has 50+ values in it and these values can change. I use the slicer to filter the data - I am always looking for the same 5 values, and my 5 values start with the same text string.
I had recorded a macro to select my 5 values. this macro selects the items that are true and then lists all the other values and sets selection as false.
When new values are added the macro crashes because I don't have an explicit line of code to set the selection of the new value to false.
I found code to select one value from the slicer and deselect all other values without having to list them all explicitly, but I can't find code to find the 5 values and deselect all other values without having to list them explicitly, or
a way to modify this code to select all slicer items that "contains" the consistent text string. either would help...
this is the code I have to find one specific value, but deselect the rest without stating them explicitly:
For Each slcCache In ActiveWorkbook.SlicerCaches
slcCache.ClearManualFilter
Next
With ActiveWorkbook.SlicerCaches("Slicer_Fruit")
For Each oSlicerItem In .SlicerItems
If oSlicerItem.Name = "abcx Apple" Then
oSlicerItem.Selected = True
Else
oSlicerItem.Selected = False
End If
Next oSlicerItem
End With
How can I change the code to select the slicer items that starts with "abcx" or contains this text?
or is there a way to select "abcx Apple" and "abcx Pear" and "abcx Banana" but not select any other values?
Try this :
Sub Slicer_select()
ActiveWorkbook.SlicerCaches("Slicer_Fruit").ClearManualFilter
Dim Sl_I As SlicerItem
For Each Sl_I In ActiveWorkbook.SlicerCaches("Slicer_Fruit").SlicerItems
If Not Sl_I.Value Like "abcx*" Then Sl_I.Selected = False
Next
End Sub
How to copy a dropdown menu (data validation) to entire column in Excel (only rows that having something else too). And, in this case, how to leave row for the header?
Ok, I found the answer and now it's working:
Sub pasteCellToColumn()
Dim lastRow As Long, i As Long
lastRow = Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
Sheets("hiddenData").Range("A1").Copy
For i = 1 To lastRow
If Len(Trim(Sheets("Sheet1").Range("A" & i).Value)) <> 0 Then
Sheets("Sheet1").Range("K" & i).PasteSpecial _
Paste:=xlPasteValidation
End If
Next i
End Sub
Instead of clicking in a cell, click on the header (A,B,C, etc) and go to: Data Tools > Data validation.
Select the entire column you want to validate
Click on "Data Validation" from the Data tab
Choose "List" from the "Allow" box
Click on the arrow to the right of the "Source" box and select the cells containing the allowed values
And you are good to go!
More on that here.
To copy and paste only the dropdown list (validation), and only to not empty cells, do the following:
Select every possible cell (including empty ones) where you want to have the dropdown menu pasted.
Hit F5, then Special..., finally Constants radio button and OK. This will select only cells which are not empty from your previous selection.
Home > Paste > Paste Special...
Validation radio button and lastly OK.
Let me know if it helps!
I have a pivot table based on PowerPivot with multiple levels in the Rows section. Quite a few of the elements are blank. Is there a way to suppress the blank rows?
My Pivot Table looks like this at the moment.
Product1
Release 1
Iteration 1
(blank)
Iteration 2
(blank)
Release 2
(blank)
(blank)
Product2
(blank)
Product3
Release 1
Iteration 1
Sprint 1
(blank)
(blank)
(blank)
This is what I want it to look like
Product1
Release 1
Iteration 1
Iteration 2
Release 2
Product2
Product3
Release 1
Iteration 1
Sprint 1
That's just an example. I've tried to set filters for each level not to display blanks but if I filter each level to hide blank fields the pivot table doesn't have any items in it. It seems that Excel ends up filtering each level out that has ANY blank values.
Not sure if I made sense or provided enough information for troubleshooting. I'm pretty much brain dead at the moment so I apologize.
Please let me know if it doesn't make sense or if I can provide any additional information to clarify what I'm trying to do and encountering.
Thanks.
EDIT: Changed the code block to be more clear and added an "after" code block to show what I want to get to. I guess the issue is that the "depth" of the rows for the entire pivot table has to be equal. For example if I have 3 indents for the first item, the others must also show 3 levels of indent worth of data. If I hide blanks and that results in 1 indent worth of data for the first item, it will hide non-blanks for other items as well if they appear after 1 indent. Still not sure if that makes any sense :) I need some sleep.
I think you should be able to check Show items with no data on rows and/or Show items with no data on columns in Display under PivotTable Options.
I ended up using a Flattened PivotTable instead from the PowerPivot "Manage" screen instead. That seemed to do what I needed.
I needed to solve exactly the same problem, but wanted the the rows to be hidden automatically when the pivottable filtering was changed or the data was refreshed, so I wrote a function called from a 'Worksheet_PivotTableUpdate' event on the sheet holding the pivottable, although you could drive it off a button if you prefer I suppose. This initially did the job by scanning down each row in the pivottable, hiding it if it was visible and didn't need to be (as the row's first cell was '(blank)'), or showing it if it was hidden and shouldn't be, otherwise just leaving it hidden or visible as it was.
However, I found the function ran very slowly, so here's my next attempt, which initially un-hides all the rows in the pivottable, then goes and finds all the blank cells in the first column, adding them to a range object, then it hides the entire row for every cell in that range. This version works about ten times as fast :-)
Pass in the name of the sheet where the pivottable reside, the name of the pivottable and an optional string to look for in the rows that need to be hidden; this defaults to '(blank)' if not supplied by the calling function.
Apologies in advance if I fall foul of anybody's variable or function naming conventions (I'm only a hacker ;-))
Sub FixBlankPivotRowsV2(ByVal SheetName As String, ByVal PivotName As String, Optional HideDefn as String = "(blank)")
Dim CurrPivot As PivotTable
Dim CurrRow As Range
Dim BlankRange As Range 'NB This is where we'll build the range of things to hide, which will initially be Nothing, as we never initialise it.
Dim oldStatusBar As Boolean
'Show a nice message in the status bar
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Hiding blank entries in " & SheetName & ", back in a sec..."
Application.ScreenUpdating = False
'Get the pivottable to work with
Set CurrPivot = ActiveWorkbook.Sheets(SheetName).PivotTables(PivotName)
'Unhide all of the pivot rows first
CurrPivot.RowRange.Rows.EntireRow.Hidden = False
'Loop around each row in the pivottable
For Each CurrRow In CurrPivot.RowRange.Rows
If CurrRow.Offset(0, 0).value = HideDefn Then
If BlankRange Is Nothing Then
'This is the first blank row we've found, so just set the range up to be the first cell of that range
Set BlankRange = CurrRow.Offset(0, 0)
Else
'Add the newly found blank row to the range using a Union
Set BlankRange = Union(BlankRange, CurrRow.Offset(0, 0))
End If
End If
Next
'Only hide things if there's anything to hide!
If BlankRange Is Nothing Then
Debug.Print "Nothing to hide!"
Else
BlankRange.EntireRow.Hidden = True
End If
'Set the status bar back the way it was
Application.ScreenUpdating = True
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
End Sub
I looked for a way to select all of the 'blanks' cells in the first column using one of the Go To Special type functions, but couldn't find anything that would fit the bill, so please let me know if you know how to do such a thing as it will speed this up even more.
I hope this helps somebody out there!
Try to select the a cell in the pivot table "blank" press delete button and press spacebar.
No idea why or how this works, but I sleclected one of the cells in the PivotTable that contained (blank), then hot spacebar. I then hit the return key, and all the (blank) cells in the same column went blank. Repeated this for the other columns in the table.
I have 2 lists in excel. First one is for searching (i want to have dropboxes), and second list is for data.
In second list I have filtered data. But what I want to do now is filter from parameters given in first list.
How can I transfer filter headers on first page?
I want to select brand on 'Search' list and results will be filtered on 'Rows' list.
I can't think of a way to do this exact thing without VBA. Certainly would love to know if there is a way, so maybe someone else can chime in.
That said, here is a small VBA procedure that will get what you want. It works based off a change in the drop down box for Brand in your Search sheet. Follow steps below to implement:
once in Excel hit Ctrl + F11 on your keyboard. This opens up the VBE
In the Project - VBAProject window in the upper left click the Object referring to the Search sheet
Paste the below code into the big window on the right referring to that sheet.
Make sure to save the file as an .xlsm file (Excel-Macro Enabled File) if using XL2007 or greater.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wksFilter As Worksheet, wks As Worksheet
Dim rngFilter As Range
'replace "A6" with the cell where the Brand dropdown is
If Target.Address = "$A$6" Then
Set wks = Sheets(Target.Parent.Name)
Set wksFilter = Sheets("Rows")
'may need to adjust the number 1 to match the exact location of your Search Column in the rows sheet
wksFilter.UsedRange.AutoFilter 1, wks.Range(Target.Address)
End If
End Sub