Excel Autofill issues - excel-2007

I have a calendar excel sheet that has week number and month numbers, but it also has ID fields for week and month. So I have week 1 which has 7 days in it with each date having a week ID of 40. If I try the auto fill to drag down it ends up going 40.1, 40.2 or some things similar. Don't use excel often. Is it possible to get it to just repeat the ID for the Week? (for example every 7 days a new id is generated?)
Thanks

Nice trick to get repeated value x times, then increase value by 1 and repeat x times, ... is to use rounded-down division of row numbers:
=INT((ROW() - row_offset) / nr_of_repeats) + initial_value
e.g. values for following formula:
=INT((ROW() - 2) / 7) + 40
A1 Header
A2 40
A3 40
A4 40
A5 40
A6 40
A7 40
A8 40
A9 41
A10 41
...
Replace ROW by COLUMN or relative reference to a cell with Day_ID as appropriate.
It might be a good idea to replace the formulas with (Paste special) values after you compute the correct numbers..

Related

Compare two columns in excel and find the differences with VBA

Hello I am trying to write a macro that compares two columns and tells me if something from the first column does not exist in the second.
A B
1 55
23 68
55 97
68 58
97 90
14
25
So I need to take the values from A and check if they are present in B, if not it shopuld give back the value from A which was not found.
Can you please help me on that
You do not need vba.
This formula will do what you are asking.
=IFERROR(AGGREGATE(15,6,$A$1:INDEX(A:A,MATCH(1E+99,A:A))/(ISERROR(MATCH($A$1:INDEX(A:A,MATCH(1E+99,A:A)),B:B,0))),ROW(1:1)),"")
Put it in the first cell of the desired output and copy down till it returns blanks.

Add value to another cell until total value reached

I need an excel formula or VBA to solve below problem. So I need you guys to help me please:)
My problem is :
I have a table as blow with given total request and values. What I need is generate new value and the total of those values should give me closest total to "Total Request"
So the generation of new values should stop when it reach >= Total request.
Given Table :
Total Request 35
Value New Value
1
2
3
14
21
12
Requested Table
Total Request 35
Value New Value
1 1
2 2
3 3
14 14
21
12
Thanks in advance :)
IF SUM in expanding range
Presuming you have Value column as column A, you can use this formula and copy down. It should stop on sum=20:
=IF(SUM($A$5:A5)<Total_Request;SUM($A$5:A5);"")
Or if you want just the value as an answer:
=IF(SUM($A$5:A5)<Total_Request;A5;"")

Add Numbers Until Value Reached

I want to have a threshold value in one cell(A1) and take it as a reference for adding cells.
Suppose I have
A1 - 10
A2 - 4
A3 - 2
A4 - 3
A5 - 4
A6 - 6
I want to add cells based on A1(Threshold).
As A1 is 10, cells from A6:A5 should be added - Result:10
If A1 is 6 then cell A6 should be returned- Result:6
If A1 is 16 then cells from A6:A3 should be added - Result:19
Is this possible without VBA? Can i get count of number of cells in return along with sum?
I've added some progression SUM operation with ROW and OFFSET for the following. Note that I have modified and added to your sample data for more thorough results.
      
The SUM formula in C2 is =SUM(OFFSET($A$2,0,0,MAX(INDEX((SUBTOTAL(9,OFFSET($A$2, 0,0,ROW(1:99),1))<$A$1)*ROW(1:99),,))+1,1)) anf the COUNT is derived in D2 with =MAX(INDEX((SUBTOTAL(9,OFFSET($A$2, 0,0,ROW(1:99),1))<$A$1)*ROW(1:99),,))+1. TBH, I didn't experiment much with zeroes in the data as I was unsure whether you would want to count them in the progression or not.
You can use the INDIRECT() function.
=SUM(INDIRECT("A6:A"&ROUNDDOWN(A1/2,0)))
for the count use
=COUNT(INDIRECT("A6:A"&ROUNDDOWN(A1/2,0)))
It's hard to hit a moving target but for your revised parameters try the following.
=SUM(OFFSET($A$6,0-MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,)),0,MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,))+1,1))
 
=MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,))+1
While Excel expects to calculate in a 'down-and-to-the-right' progression, the OFFSET() function will accept parameters to both relocate the starting point and reshape the height and width of the range of cells being summed. Generally, working 'down-and-to-the-right' will allow to leave some breathing room for expansion but you will have to be very careful that you do not attempt to move upwards past row 1 (#REF! error).
OFFSET function
The formula could be simplified if there was any guarantee that nothing of numerical value was ever going to be below A6 but that point has not been addressed so my formulas halt the sum operation at A6.

Excel VBA: Move row to a destination regardless of row count in pivot table

I am new to VBA and have very basic knowledge. I have a pivot table which calculates the count of students grouped by enrollment date and columns consists of Brand Ids
I want to move a row to the end of the pivot table and the number of rows keeps changing. I tried below code but I can use that only when number of rows in pivot table are constant. Can someone please help me to move row to the end of the table though the number of rows are not constant?
ActiveSheet.PivotTables("StudentCount").PivotSelect "'En_Date'['(blank)']", _
xlDataAndLabel + xlFirstRow, True
ActiveSheet.PivotTables("StudentCount").PivotFields("En_Date").PivtoItems( _
"(blank)").Position = 20
'In current sheet I need to move to 20 but actually 20 is not constant
ActiveSheet.PivotTables("StudentCOunt").PivotSelect "En_Date", xlButton, True
I tried below code as well but it is not working:
Dim LS as LONG
LS = ActiveSheet.PivotTable("StudentCount").TableRange2.Rows.Count
ActiveSheet.PivotTables("StudentCount").PivotSelect "'En_Date'['(blank)']", _
xlDataAndLabel + xlFirstRow, True
ActiveSheet.PivotTables("StudentCount").PivotFields("En_Date").PivtoItems( _
"(blank)").Position = "& (LS - 1)"
ActiveSheet.PivotTables("StudentCOunt").PivotSelect "En_Date", xlButton, True
Pivot Table:
Count Of Students
Date A1 A2 A3 A4 Blank Grand TOtal
blank 69 86 23 45 223
01/01/2014 2 25 3 1 31
02/01/2014 1 2 5 8 16
Grand Total 71 112 28 51 262
Hi to answer your question, you do not need VBA to do this.
The reason your pivot is behaving as such is because your Dates are actually not Dates but Dates Entered as Text. See below recreated data:
Re-entering it as actual dates will solve your problem.
So after changing the Text Dates to actual Dates, your pivot sorts your row as you like.
See below:
Hope the solution I presented helps you a bit.
Additional: If however re-entering all the dates is not convenient, try below code:
Dim i As Integer
With ActiveSheet.PivotTables("StudentCount").PivotFields("En Date")
For i = 1 To .PivotItems.Count
If .PivotItems(i) = "(blank)" Then .PivotItems(i).Position = .PivotItems.Count
Next
End With
The code above simply iterates through all the PivotItems, looks for (blanks).
It then change it's position to the last position which is equal to .PivotItems.Count.
Hope this works for you.

convert two number to a range

I am going create a macro to convert two number to a range, e.g.
On excel cell A1 and A2, I input integer 1 and 5 respectively. The output will look like:
A3 1
A4 2
A5 3
A6 4
A7 5
How can I do that?
You can accomplish this without even using macros :)
in A3 type your first number.
On the Home tab go to the Editing section > Fill > Series...
Choose to have your series populated in Columns. Choose a stop value of 20 (or whatever)
Click OK
Now you will have a series of numbers 1-20 going down starting in Cell A3.
You can change your step value so that each number is incremented by 1, or 2 or 3 or whatever. You can also fill in rows instead of columns.
If you need it more automated than that just do all of that while recording a macro and see what it does then change the VBA to suit you more specific needs/come back here with some code to get advice on.
The Below COde will read the Content from the A1 and A2. According to the range it will display the result in the A series only.
enter code here
For i = Cells(1, 1) To Cells(1, 2)
Cells(1, i + 2) = i
Next i