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.
Related
I'm creating an excel workbook that has a dashboard on the front page of it. when two dates are selected from a drop down and the "refresh data" button is pressed, it runs a macro that fills in all the charts and tables on the dashboard page based on data tables in other worksheets within the workbook.
I'm trying to add a layer of dynamism so that if a date is selected where not all information, or even any information, is to be found, it lets the user know. (some information can be late coming to the work book)
So far I've tried a few ways with the closest maybe being the following options, but none of them work properly.
The beginning code is
Sub Macro3()
Dim DataM As Variant
Dim DataY As Variant
Dim ws1 As Worksheet
Dim DD1 As OLEObject
Dim DD2 As OLEObject
Dim i As Byte
Set ws1 = Worksheets("KPI Dashboard")
Set DD1 = ws1.OLEObjects("DMonth") 'this is the month input
Set DD2 = ws1.OLEObjects("Dyear") 'this is the year input
Set DataM = DD1.Object
Set DataY = DD2.Object
'part 1 is for utilisation
Set ws2 = Worksheets("People Info")
ws2.ListObjects("Utilisation").Range.AutoFilter Field:=2, Criteria1:=DataM.Value
ws2.ListObjects("Utilisation").Range.AutoFilter Field:=1, Criteria1:=DataY.Value
My first attempt was to count the rows in the databodyrange, but every time I tried that I would get an error saying there was no cells. I know I oculd normally put an "on error" line of code, but I want it to highlight to the user that there is a table missing data and then go onto the next table and keep going. I don't know of any ways in which I could dynamically have error responses in one function to the same error.
My second attempt was to just count the tables overall rows, with a msgbox to say there was no data like below:
If ws2.ListObjects("Utilisation").Range.SpecialCells(xlCellTypeVisible).Rows.Count = 1 Then
If MsgBox("It Looks like we have no data for Utilisation, please fill it in and run it again. do you want to continue?", vbYesNo) = vbNo Then
Exit Sub
End If
ws2.ListObjects("Utilisation").AutoFilter.ShowAllData
GoTo S1P2
End If
But it always returns the count of rows as 1, even when I can see that it clearly has 5 or 6 rows in it.
So the last thing I tried was to select the area, and see if I could count that selection to greater success, but again it would still return 1, even on the count
Can anyone think of a better way to try it?
I have also tried using the IsEmpty() function and a handful of others like that but can't seem to get it to work. it either says there are no cells in the databody range, because they have been queried out or it says there is 1 row in the table range, even when there isn't.
Any help on how to make it work, or even a different avenue with which to look down would be really helpful.
I have 2 drop down boxes and a button. Drop box 1 has numbers from 1 to 30, and Drop box 2 has numbers from 1 to 130.
What I need is a way to take the value of Drop box 2 and - having Drop box 1's value as a row number - paste it into the C column of another sheet, allowing for live data editing.
Note: I am a complete noob to VB. The Drop down boxes and button are on the chart sheet if that makes it any different. Also I have to have the drop boxes on the chart sheet, not the data sheet.
I have tried selecting drop box values however am unable to figure out the correct way to do so. Things such as DropBox2.Value & DropBox2.Value.Select don't seem to work (most likely doing it wrong). Googled various ways of how to get drop box value and paste elsewhere but to no avail. Apologies for wasting anyone's time if this seems mundane.
Sub TEST()
' TEST Macro
Sheets("Sheet1").Select
DropBox2.Value.Select
ActiveSheet.Cell("$C""DropBox1.Value").Select
Selection.Paste
Chart2.Select
End Sub
Expected to do what I said in the description however the error message
Object required
appears.
Try the below code:
Sub TEST()
Dim varDrowDown1 As Variant: varDrowDown1 = ThisWorkbook.Worksheets("Sheet1").Shapes("Drop Down 1").OLEFormat.Object.Value
Dim varDrowDown2 As Variant: varDrowDown2 = ThisWorkbook.Worksheets("Sheet1").Shapes("Drop Down 2").OLEFormat.Object.Value
ThisWorkbook.Worksheets("Sheet2").Cells(varDrowDown1, 1).Value = varDrowDown2
End Sub
Check that the names of the objects are correct. I assumed Sheet1 is where the Drop Down Boxes are, Drop Down 1 and Drop Down 2 are their names, Sheet2 is the Worksheet where you want to copy the Value to, and you would like to insert it into the first column.
You can find the name of your Drop Down Boxes by right clicking them and looking at the place where the Active Cell's reference (e.g. A1) usually appears. The Sheets' Name is trivial, and you should know the column's number, too.
Sheets("Chart2").Select
Dim varDropDown1 As Variant: varDropDown1 = ThisWorkbook.Sheets("Chart2").Shapes("DropDown1").OLEFormat.Object.Value
Dim varDropDown2 As Variant: varDropDown2 = ThisWorkbook.Sheets("Chart2").Shapes("DropDown2").OLEFormat.Object.Value
ThisWorkbook.Worksheets("Sheet1").Cells(varDropDown1, 3).Value = varDropDown2
Sorted, thank you for all of your help!
I am setting up a receipt printout from Excel 2010. I have multiple items on the worksheet and can print everything ok.
The receipt is to be printed in a busy environment and as such we just want the operators to enter the numbers and press CTRL+P.
Not all the items on the receipt will be used:
Item 1 10:00
Item 2 0.00 <--- This is an example of the row I do not want to print
Item 3 10.00
Total 20.00
The number of items could increase over time so the solution must be able to include the entire print range. Use of the hide function is not an option as it takes to long.
The solution must require no action by the user as they are not 'computer people'.
All cells are locked except those which require data to be entered to minimise input errors. i.e. VAT calculations
I had tried a VB routine but with no luck, hence the question.
EDIT: The VB I had written was-
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim RngCol As Range
Dim i As Range
Set RngCol = Range("B1", Range("B" & Rows.Count). _
End(xlUp).Address)
For Each i In RngCol
If i.Value = 0 Then
i.EntireRow.Hidden = True
End If
Next i End Sub
I have tried Jeeped's suggestion but some how the page size has now changed - won't change back either?
Although Jeeped's suggestion has done what I wanted it is now ignoring the header which is needed although I can move the info to the main sheet.
Use a conditional format rule. I always use rules based on formulas like =NOT($D1) to cover columns A:E depending on the value in column D but any of the others will do if you can determine criteria that equals zero. When you decide on how you want to handle the criteria, click Format and go to the Number tab. Choose Custom from the list down teh left and use ;;; (three semi-colons) for the Type:.
Click OK to accept the format and then OK to create the rule. Nothing in A:E will be visible if there is a blank or 0 in column D.
Alternate AutoFilter Method:
The individual worksheets do not have any standard events to do with printing but the workbook has a BeforePrint Event.
Go the workbook's VBE and locate ThisWorkbook in the Project Explorer then double-click it. Paste the following into the new pane on the right titled something like ThisWorkbook (Code).
Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = False
With Worksheets("Sheet2")
If .AutoFilterMode Then .AutoFilterMode = False
With .Range(.Cells(1, 2), .Cells(Rows.Count, 2).End(xlUp))
.AutoFilter Field:=1, VisibleDropDown:=False, _
Criteria1:="<>0.00", Operator:=xlAnd, Criteria2:="<>"
End With
End With
End Sub
Edit to suit the actual column that holds the numbers. I've used column B. Note that the AutoFilter requires a header row.
Tap Alt+Q to return to your worksheet. Any method of printing the page will result in the AutoFilter Method being applied to column B and hiding any blanks or zeroes (in the form of 0.00) in that column.
Before:
After:
As you can see from the sample images, printing to a .PDF filters the code column. I've also chosen not to display the little drop-down arrow normally associated with an AutoFilter.
You can unhide the rows with conventional unhide commands, clear the filter or just turn the autofilter off to get the rows back.
This latter method is a bit more involved but it gets rid of (aka hides or filters out) the undesired rows rather than simply not displaying the text in them. If need be, the worksheet could be unprotected for the duration of the print cycle.
I have a spreadsheet that has a tab for each research location. There is a section on the sheet that has several columns. Three of the columns are as follows: 1 lists action items (text) 1 lists who is responsible (text) and 1 lists the due date (date field). The rows in this same "table" represent categories. In many cases there is an action item only in one or two categories or maybe none at all for some.
I would like to query each tab that represents a research site and pull any action items, the responsible party and date onto another tab so that we can see all action items in one place for all the sites vs. going tab by tab to review.
I thought some sort of IF or VLOOKUP function might work, or some sort of pivot table but because it is text and not numbers I am having a hard time crafting the appropriate formula. I was also told I could do some sort of reference look up (like putting a word like ACTION at the start of any text I want to find later) but this seems more complicated than it needs to be.
Any help would be deeply appreciated.
I don't think VLOOKUP can solve your problem. You definitely need VBA so something like this will get you going. Make a new sheet called as Summary and put this code in the sheet:
Sub SummarizeSheets()
Dim ws As Worksheet
Application.ScreenUpdating = False
Sheets("Summary").Activate
Range("A2").Select
For Each ws In Worksheets
If ws.Name <> "Summary" Then
If ws.Range("A2") <> "" Then 'A2 is blank means no action items found so go to next worksheet
ws.Range("A2:C100000").Copy 'Adjust your range here
ActiveSheet.Paste Range("A65536").End(xlUp).Offset(2, 0)' Paste the copied range
End If
End If
Next ws
Application.CutCopyMode = False
End Sub
You have to adjust the code to suit your needs. Assumption here is your action items starts with cell A2 and responsible person and due date are in cell B2 and C2 respectively.
I need Help!
I am not well versed in VBA or Macros but i cannot find any other way to accomplish what i need to do without using it.
I have a sheet which i will be using to track Purchase orders, and what i need to do is; when i have a row in sheet 1 (Purchase Orders) which has been recieved i.e. the date of receipt has been recorded in column H i need for the entire row to be cut and pasted into sheet 2 (Received orders).
The header takes up the first 7 rows the rows, so i need the macro to look at rows 8-54. Once the received items are removed from sheet 1, i need the row to also be deleted or preferably for the list to be sorted by column A moving the now empty row which has been cut from open for a future entry.
Any help would be greatly appreciated.
The "Record Macro" feature should be enough to do the task you describe.. In Excel 2007, go to the Developer tab in the Ribbon, and select "Record Macro", and perform exactly the steps you are describing. It will record the equivalent VBA code, which you can then execute - or tweak/modify.
I tested this out, here's one way to do it:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim receivedDate As Range, nextOpen As Range, isect As Range
Set receivedDate = Sheet1.Range("H8:H54")
Set isect = Application.Intersect(Target, receivedDate)
If Not (isect Is Nothing) And IsDate(Target) = True Then
Set nextOpen = Sheet2.Range("A1").End(xlDown).Offset(1, 0)
Target.EntireRow.Copy Destination:=nextOpen.EntireRow
Target.EntireRow.Delete
End If
Application.EnableEvents = True
End Sub
This would be pasted into the Sheet1 code. Any time a cell is changed on sheet1, the code checks to see if it's in the critical range that you specified. (H8:H54) If it is, it then checks to see if it's a date. If it is, it then copies the entire row, puts it in the next open row on Sheet2, and deletes the original row. The cells below it will get shifted up so there are no gaps.
Since the code functions on a cell changing event, it disables "Application.EnableEvents" in order to avoid a loop of changing a cell to call an event which changes a cell to call an event... etc.