How to insert 'n' number of rows on a sperate sheet based on 'n' being a number in a cell - vba

I have to make my teams workload each month. It changes, based on number of working days how many auditors there will be available, and how may audits are needed for each company. If i can have the sheet auto balance the load based on how many total audits are needed for each company, then determine how many working days a person might have in the month that would be amazing.
But for now - I would really like to be able to have it create a separate sheet for each auditor with their name in column A and the name of the account in column B based on how many audits they have been assigned.

You may have to modify this a little for your needs...
workbook.sheet("yoursheet").rows(startRow & ":" & startRow+numberOfRowsYouWant).Insert Shift:=xlDown
If you want to insert 5 lines at row 60, for example:
workbook.sheet("yoursheet").rows("60:" & 60+5).Insert Shift:=xlDown
Let me know if this doesn't work.

Related

Update Excel Pivot Table Fields

I compile morning reports every day using a workbook with a number of different sheets and pivot tables. So far, I have been able to somewhat automate the data retrieval process, and getting the pivot table data to refresh was very simple. What I would like to do now is get the pivot table field filters to change automatically to include the data entries for thirty days prior up to and including today's date. I have seen some things out there that let you select just one date, but I need to select a range. I have tried using a relatively recorded macro, but it gives me this
Sub Update()
Sheets("Doorline Month").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveSheet.PivotTables(-1).PivotFields("Date").CurrentPage = "(All)"
With ActiveChart.PivotLayout.PivotTable.PivotFields("Date")
.PivotItems("1/14/2018").Visible = False
.PivotItems("2/15/2018").Visible = True
End With
End Sub
I believe that this would only deselect 1/14/2018 and make 2/15/18 visible. I want this code to work automatically every morning, so if I come in on 2/16/2018 it deselects 1/15/2018 and selects 2/16/2018. I have tried replacing the dates in the recorded macro with "ActiveCell" but to no avail. Any help is greatly appreciated. If it helps, the data for my pivot tables is in sheet 1 and the dates specifically are in column A. Unfortunately, the number of data entries per day is not consistent so I don't know if that complicates things or not.
Why dont you put a flag in the database/ data of origin that marks with 1 or 0 each line depending if the date is within the range you want or not? Then you can leave the 1 or the 0 selected in the pivot table's filter field and the relevant data would show automatically every time you refresh.

Group Entire Crystal Report by Column in Subreport

I am trying to set up the following report so that it is grouped first by "Transfer-In Unit" (d1_10.xinstitute), which is the title of a column that is included in a sub-report, and second by xpid, which is a patient index number used in all tables (except a catalog) in this report. To simplify this question, assume that xpid is indexed in alphabetical order of the patients' names.
See info/examples below:
This report shows patients that have transferred out of a specific unit since the user-inputted date (Name), a row for each date that the patient transferred out of a particular unit (Unit M Transfer-Out Date), chronologically where they next transferred into (Transfer-In Unit), and when they transferred into that unit (Transfer-In Date).
Currently without attempting this grouping the output looks like this:
Name and Unit M Transfer-Out Date are on the parent report
Transfer-In Unit and Transfer-In Date are in a subreport because they both call d1_10.dstartdate but with different criteria.
The goal is to sort by Transfer-In Unit, which is a column in the subreport.
The output should be:
An underlying issue is that to select the chronological next transfer-in following a transfer-out, I have to select a minimum transfer date grouped by xpid. This causes the requirement of an xpid grouping in the sub-report.
I have tried a grouping by d1_10.xinstitute (the unit index) in both the parent- and sub-reports. In the parent report it creates one all-encompassing group, because every row in this report represents someone transferring out of "Unit M". In the subreport it seems to apply the groupings row by row, so each row has two groups, even when the next row is the same patient transferring into the same unit. However this is my best attempt and it looks like this:
Any help/thoughts/ideas much appreciated. Let me know if I can provide any further info.
Thanks

Powerpivot one to many filter column

I have 2 tables, a visit table and then a diagnosis table. Visit is my one and diagnosis is my many (you can have secondary and tertiary diagnosis).
I have over 50 measures created in the visit table. Because of this, I simply want to create a flag on my visit table in the form of a column that will filter down my results based upon selections from the Diagnosis table. I have seen formulas for measures that use =calculate([cases],DXCodes) which will filter down the cases to only those that relate to the DXCodes and this works, but I don't want to have to build this in for every measure. Instead I want a DXFlag that will flag my visit rows with a 1 if what I selected from Diagnosis exists in the Visit table. Suggestions? I can get more specific if this is not making sense
Making some assumptions about your data, you could have tables like this:
And if you create a measure to pick out each of the diagnoses:
[diag1]:=FIRSTNONBLANK(Visits[Primary Diag],1)
[diag2]:=FIRSTNONBLANK(Visits[Secondary Diag],1)
[diag3]:=FIRSTNONBLANK(Visits[Tertiary Diag],1)
Then add this measure to flag your visit rows:
[Found]:=MAXX(ALLSELECTED(Diagnoses[Diagnosis]),IF(FIRSTNONBLANK(Diagnoses[Diagnosis],1)=[Diag1]||FIRSTNONBLANK(Diagnoses[Diagnosis],1)=[Diag2]||FIRSTNONBLANK(Diagnoses[Diagnosis],1)=[Diag3],1,BLANK()))
This gives you this result:
Edit: Response to revised/clarified requirements
I've been trying to see if I can get a calculated column to take account of the diagnosis selection with little success. Doing it with a measure is fairly straightforward:
[Diag Flag]:=IF(CALCULATE(COUNTROWS(DiagnosisTable),FIRSTNONBLANK(DiagnosisTable[Diagnosis],1))>0,1)
But this approach would require you to revise all the measures you wish to appear on your output summary. If it's just the total number of visits and the sum of the length of stay, that's not difficult, but if you need to revise all 50 measures it's a bit less appealing.
Here are the new measures for the number of visits and the length of stay which I have shown in a separate PivotTable on the same sheet:
[Cases]:=SUMX('Visits',[Diag Flag])
[LengthSum]:=SUMX('Visits',Visits[Length of Stay]*[Diag Flag])
And the output:
NOTE: My slicer is connected to both tables.

Making Excel report into SSRS with Pivot Tables

I am trying to create a SSRS report from an ad hoc script I have. I can get results but the user of the report requests certain pivots that I can not seem to correctly display the information.
Below is an export of the report from sql with the pivots added. I want each row to be grouped by the GRADE first, OD second, and ID third. The pivot is adjusted for the STOCK NUMBERs. Each row with matching grade,OD, and ID will have numerous stock numbers.
http://i.imgur.com/Bx3yMuX.png
This is the closest I have have came to displaying the information in SSRS.
http://i.imgur.com/hpajKmB.png
Is there anyway I can have the Stock numbers run across a single row instead of a row for each stock number?
I would create a Column Group based on Stock number. That will generate a column for each Stock number.
It was a little more tricky than I thought. Since I did not want the Stock Number to actually be a column header but to just list on each column corresponding to my group it was not an actual pivot and was why it was not working properly.
Basically to get it to work I had to use the LookUpSet+Join function in SSRS to list the stock numbers out. I was not required to list them out on different columns. Thank-you for your replies.
Here is the code I used in the column
=Join(LookupSet(Fields!grade.Value & Fields!od.Value & Fields!wall.Value & Fields!id.Value, Fields!grade.Value & Fields!od.Value & Fields!wall.Value & Fields!id.Value, RTrim(Fields!stock_number.Value), "FOC"), ", ")

Excel: Selecting Specific Columns and Rows in Pivot Table and Formatting

I'm using a Pivot Table in Excel 2010, and while searching posts I find that a lot of users are frustrated like me because it doesn't keep all formats.
So what I'm trying to do is run a macro that formats columns in a Pivot table, but limited to the last row and column in the table. I have the formatting info, but I just need to know how to apply it to specific columns and rows.
What I was thinking might work is finding the last column of the Values row, in this case "Stops per Rte" which is the last Values column; however, I have months listed at the top, so it repeats across months. If the user filters only certain months then the # of columns will decrease.
Same goes for the # of rows: of course, the user should be able to expand/collapse rows as needed, so I only want the column format to go to the last row or just above "Grand Total", if possible.
Hopefully, this makes sense. Thanks in advance! = )