Adding 1 to existing number in a cell based on value of another cell - vba

Alright so I looked through for other solutions but I didn't get anything close enough with my limited knowledge to make it work so I hoping some geniuses here can help.
Basically I am using excel to autoupdate some data based on the value of another cell. A simplified version of my table looks like the below:
ID Step Count
526985 - Step 1 8
123569 + Step 3 3
589745 - Not in AMP 1
589465 + Step 2 5
IDs are unique and always 6 digits (just fyi if that helps anything). There will never be a Step column or count column value without an ID value
I would like to use the change val in vba so it changes as I go along automatically
The goal is for the user to not have to update manually the value in the "Count" column
When the user starts working on the sheet, the "Step" column will be blank and will be selected from a drop down menu but the "Count" and "ID" will be populated already
What I need:
When a value of "+ Step 1", "+ Step 2", "+ Step 3", "+ Step 3 ext", "- Step 2", "- Step 1" is selected in the "Step" column for an ID, I need "+1" added to whatever the current value is in the "count" column
When a value of "- Not in AMP" is selected from the "Step" column, I need the value to be 0 in the "Count" column
There will be other values selectable from the "Step" column which I need to be ignored (Keep the same "Count" column value)
After a step value has been selected in the "Step" column and the "count" column has been updated. I still need to be able to go back and change that value to any other number manually.
I think that's about it. I thought of using formulas which I could do but the issue is where I need to be able to overwrite the value with another, it will delete the formula. I'm open to anything that makes this work though. Thank you in advance!

After you have a Change event you could have some logic to check:
- if user is adding a new value in the correct column, you would load the previous data into a variant to perform the logic that you have given to populate the addition cells
- if not, let the user update the values.

Related

VBA Code Sample to Look Up Multiple Criteria

Am hoping I can get some help with a VBA code sample to look up specific values in multiple columns (4 to be exact) and populate a specific text in another column (outside of the first 4). This is all happening within 1 single worksheet. See below for 4 criteria and specified verbiage to be populated:
column 1 value: "Yes"
column 2 value: "Yes"
column 3 value: "R" or "S"
column 4 value: Begins with "9" or "88"
IF all criteria are met, then populate "AWP Review".
I use my excel in spanish, but I'll try to translate the fomula
I guess you can write this formula to filter and copy and paste later
other way would be record a macro, filtering from left to right using your criteria
if I have a wrong idea let me know
=SI(SUMA(CONTAR.SI.CONJUNTO(A2,"YES",B2,"YES"),SI(O(C2="R",C2="S"),1,0),SI(O(D2=9,D2=88),1,0))=3,"SOME TEXT","")
=IF(SUM(COUNT.IFS(A2,"YES",B2,"YES"),IF(OR(C2="R",C2="S"),1,0),IF(OR(D2=9,D2=88),1,0))=3,"SOME TEXT","")

Extracting "hidden" data from expanding/collapsing pivot table - Excel

I'm not sure if this is possible but as you can see I have a pivot table with multiple dependent and expandable fields. I am trying to concatenate the data from columns A:D into one cell which works fine in row 2 but doesn't work with blank parent cells, as you can see in column F.
Any ideas for how to achieve this?
Pivot table
This answer assumes that you don't want to just Repeat All Item Labels in the PivotTable from the "Report Layout" drop-down on the Pivt Table Tools "Design" tab.
A formula to get the first non-blank value on or above the same row as the current cell from Column B can be constructed with a combination of AGGREGATE, SUMPRODUCT and OFFSET, like so:
=OFFSET($B2,SUMPRODUCT(AGGREGATE(14,6,ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0),1))-ROW(),0)
How does it work?
Starting with the outermost part, OFFSET($B2, VALUE, 0) - this will start in cell B2, then look up or down by VALUE rows to get the value.
Next we need to know how many rows we will need to look up-or-down. Now, if we can work out the bottom-most row with data, we can subtract the current ROW() from that, giving us OFFSET($B2, NON_BLANK-ROW(),0)
So, to finish up we need to work out which rows are not blank, AND which rows are on-or-above our current row, then take the largest of those. This is going to take an ArrayFormula, but we can use SUMPRODUCT to make that calculate properly. To find the largest number we could use MAX or LARGE - but we get less errors if we pick AGGREGATE(14,6,..,1). (The 14 means "we want the kth largest number", the 6 means "ignore error values", and the 1 is k - so "we want the largest number, ignoring errors")
But, what list of numbers are we going to look at, I don't hear you ask. Well, we want the ROW for output from our range (I'm using $B$1:$B$100, because using the whole column B would take far to long to calculate repeatedly), a comparison against the current ROW(), and check that the LENgth is > 0. Those last two are comparisons, so let's write them out first:
ROW($B$1:$B100)<=ROW()
and
LEN($B$1:$B$100)>0
We want to use -- to convert TRUE and FALSE to 1 and 0 - this means that any "bad" values become 0, and any "good" values are larger than 0:
ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0)
This gives us the Row number when the Row is on-or-before the current row AND Column B is not blank - if either of those are False, then we get 0 instead. Stick that in the AGGREGATE to find the largest number:
AGGREGATE(14, 6, ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0), 1)
Then put it in a SUMPRODUCT to force Excel to treat it as an ArrayFormula, and that's your NON_BLANK. This then gives you that first formula right at the top of the post

Macro excel: Paste values and update 2 cells

I apologize for being newbie as I am having difficulty with this concept. I really don't know where to start.
I just need a code in Sheet2 using an 'Update Button' to do the following:
In sheet1, this information will come from different Team Leaders as duplicate or even triplicate records shown in example 'Seat no. 1.2' can occur.
In sheet2, under 'Seat No.', this is constant and will never change (serves as my reference for my other Pivot and lookup codes)
In sheet2 columns, under 'User 1', the code will paste the 1st value detected; Under 'User2', the code will paste the 2nd value detected; Under unassign, the code will paste the 3rd value detected
In sheet2 column under Status, it will show Solo if only 1user, 'Sharing' if there are 2 users and 'Vacant' if no user.
Note: only two users are allowed for every Seat No.
Hope you can help me. Thank you so much
You don't need to use macro for this. In user 1 column use this:
=IF(ISERROR(VLOOKUP(Sheet2!A2,Sheet1!$A$2:$B$50,2,0)),"",VLOOKUP(Sheet2!A2,Sheet1!$A$2:$B$50,2,0)),
where 50 replace with number of your rows.
In user 2 use this:
=IF(SUMIF(Sheet1!$A$2:$A$50,Sheet2!A2)>1,IF(ISERROR(VLOOKUP(Sheet2!A2,OFFSET(Sheet1!$A$2,MATCH(Sheet2!A2,Sheet1!$A$2:$A$50,0),0,50-MATCH(Sheet2!A2,Sheet1!$A$2:$A$50,0),2),2,0)),"",VLOOKUP(Sheet2!A2,OFFSET(Sheet1!$A$2,MATCH(Sheet2!A2,Sheet1!$A$2:$A$50,0),0,7-MATCH(Sheet2!A2,Sheet1!$A$2:$A$50,0),2),2,0)),"")
and again replace 50 with number of your rows.
In status column, use IF with SUMIF.
And in Unassign column, use vlookup like in first column, but from down to up. There is lot of articles about it. Dont forget to use if in start, which will check if there is 3 IDs for seat.
This doesn't need VBA unless you insist to do so:
User1 column:
=IFERROR(IF(VLOOKUP(A2,Sheet1!$A$2:$B$9,2,0)=0,"",VLOOKUP(A2,Sheet1!$A$2:$B$9,2,0)),"")
User2 column (array formula, press Ctrl + Shift + Enter keys simultaneously):
=IFERROR(INDEX(Sheet1!$B$2:$B$9,SMALL(IF($A2=Sheet1!$A$2:$A$9,ROW(Sheet1!$A$2:$A$9)-ROW($A$2)+1),2)),"")
Status column:
=IF(COUNT(B2:C2)=0,"Vacant",IF(COUNT(B2:C2)=1,"Solo","Sharing"))
Unassign column (array formula, press Ctrl + Shift + Enter keys simultaneously):
=IFERROR(INDEX(Sheet1!$B$2:$B$9,SMALL(IF($A2=Sheet1!$A$2:$A$9,ROW(Sheet1!$A$2:$A$9)-ROW($A$2)+1),3)),"")
Hope this helps.

Creating new rows by combining existing rows excel

I am fairly new here, so if this go against the rules please tell me.
I have an issue that seems pretty simple but I wanted to check to make sure. I have been trying to see if I could create a new row by combining every variable from one column with another, like so:
Column 1 Column 2 Combined
A 1 A1
B 2 A2
3 A3
B1
B2
B3
But instead of typing the combinations manually, I wanted the combined column make this combination without user input and to update automatically whenever column 1 or 2 has a row added or removed. I have been trying to figure out if there is some way to use the concatenate function in excel or the & sign but neither methods seems to work. I was thinking trying to code this in visual basics.
The main question: is this possible to do in excel? If so which function(s) could I use?
This assumes your data has one header row (row 1), Column 1 is column 'A' and Column 2 is Column 'B'. Place the formula below in an empty cell and copy down as far as your data permits.
=INDEX(A:A,INT((ROW(A2)+1)/(COUNTA(B:B)-1))+1)&INDEX(B:B,MOD(ROW(A2)-2,3)+1+1)
now if you want to add a little flag to let you know you have more row than you need for your data you could add the following:
=IF(ROW(A2)-1>(COUNTA(A:A)-1)*(COUNTA(B:B)-1),"Data Exceeded",INDEX(A:A,INT((ROW(A2)+1)/(COUNTA(B:B)-1))+1)&INDEX(B:B,MOD(ROW(A2)-2,3)+1+1))
According to: https://www.extendoffice.com/documents/excel/3097-excel-list-all-possible-combinations.html
You can use this formula:
=IF(ROW()-ROW(**$D$1**)+1>COUNTA(**$A$1:$A$4**)*COUNTA(**$B$1:$B$3**),"",INDEX(**$A$1:$A$4**,INT((ROW()-ROW(**$D$1**))/COUNTA(**$B$1:$B$3**)+1))&INDEX(**$B$1:$B$3**,MOD(ROW()-ROW($D$1),COUNTA(**$B$1:$B$3**))+1))
In the above formula, $A$1:$A$4, are the first column values, and
$B$1:$B$3 are the second list values which you want to list all their
possible combinations, the $D$1 is the cell that you put the formula,
you can change the cell references to your need.
In your case, you should use:
=IF(ROW()-ROW($C$2)+1>COUNTA($A$2:$A$3)*COUNTA($B$2:$B$4),"",INDEX($A$2:$A$3,INT((ROW()-ROW($C$2))/COUNTA($B$2:$B$4)+1))&INDEX($B$2:$B$4,MOD(ROW()-ROW($C$2),COUNTA($B$2:$B$4))+1))

Dynamic reference in excel formula

I have the following array formula which works for what I want to do but I'm trying to change the formula when a user selects a value.
=INDEX($A$2:$B$70,SMALL(IF($A$2:$B$70=$A$121,ROW($A$2:$B$70)),ROW(1:1))-1,1)
It's used for a monthly report and the user will choose from a drop down the day of the month, e.g 1,2,3 - 31.
So if the user selects 1 from the drop down menu I want the formula to use the above formula.
If they select 2 for example I want the formula to move over a column so it would change to
=INDEX($A$2:$C$70,SMALL(IF($A$2:$C$70=$A$121,ROW($A$2:$C$70)),ROW(1:1))-1,1)
and so on moving over a column at a time.
It this possible at all or can it even be done without VBA?
I have an example of what I want done on the following link
https://docs.google.com/spreadsheets/d/1MDOzoQxYLgW-UOyljZsMwSu8zyAB7O2k1V-bTNP5_F0/edit?usp=sharing
All the data is on the first tab called staff. Each employee has a row and the duty assigned under the corresponding day column.
On the Roster tab it summarises each day. So what I am trying to get to happen is when you choose the day of the month (or preferably the actual date) the sheet changes to reflect the data.
At the moment the code I have working does for just Day 1 because the column references are coded into the formula. I was hoping to somehow choose 6 for example from the drop down and then the formula will map chosen day to the corresponding range in the raw data and update the formula and change the formula from Staff!$A$2:$B$68 to Staff!$A$2:$G$68.
If the formula finds no more entries if shows #NUM! but I intended to use the function ISERROR() to replace #NUM! with "".
This is what I'm trying to achieve it if makes sense?
There are a few issues here/ You are returning the value from column A so the first range can be $A$2:$A$70 and that means you don't need the 1 to specify the column_num. The IF statement was covering A2:C70 when you really only want either B2:70 or C2:C70 depending on the 1 or 2.
Assuming that A122 has either a 1 or 2 in it then,
=INDEX($A$2:$A$70, SMALL(IF(INDEX($B$2:$C$70, 0, $A$122) = $A$121, ROW($1:$69)), ROW(1:1)))
Standard non-array alternative,
=INDEX($A$2:$A$70, SMALL(INDEX(ROW($1:$69)+(INDEX($B$2:$C$70, 0, $A$122) <> $A$121)*1E+99,, ), ROW(1:1)))