Finding next incremental value in MS Excel - excel

I have an MS Excel worksheet which is used for recording systems requirements and the requirements are coded with ID as shown in the image below.
I would like the excel to give me the next ID automatically as soon as I input the description. This helps me the hassle of writing the next ID as you may see that some ID are incremental on rows. eg: row 44 & 49.
To explain the image. If a user requirement has an exception, that exception will have its own user requirement. Which is why it becomes tough for me to identify the next ID.
I did try =RIGHT(INDIRECT("J" & ROW() - 1),3) to get the current max based previous row value, however, it was hard for me to get max of the AB column.
If I write the description in row K, it should write the code in the corresponding J column based on the ID's in J & AB column. Same I would like to achieve when I enter a description in AC column, it should get the next code and write it in the corresponding AB column.
I am not really sure if there is any function that can help or do we need macros to perform that.

Related

Fill data into other blank cells within predefined group of data with data from that defined group

I am developing some data sheet to check process control limits. I've could develop the system as required. But I like to increase the performance in there. Part of the data sheet that I've developed will described below.
LSL & USL Limits are as mention in above the table for ID. First I've extract the data into Help Col 01(Col V) which are within limits using below formula.
=IF(AND(U15>=950,U15<=1150),U15,"")
After then I've inserted
=IFERROR(INDEX($V$15:$V$30,SMALL(IF($V$15:$V$30<>"",ROW($V$15:$V$30)-ROW($V$15)+1),T15)),"")
formula into Help Col 02(Col W), I've removed blank cells. Next task was to add filtered Help Col 2 data into each cell into Final data list column according to the group. Groups are described here.
Group 1 = 1-4,Group 2 = 5-8,Group 3 = 9-12,Group 4 = 13-16,
I could approached that task using below formula.
=INDEX($W$15:$W$30,MATCH(INT(T15/4.25)+1,$T$15:$T$30,0))
My problem is, not possible to merge these formula together due to second formula. If anybody have an idea to merge 1st & 2nd formula into 3rd formula. Any answers are welcome here.
In V4, formula copied down :
=IFERROR(INDEX(AGGREGATE(14,6,U$4:U$99/(U$4:U$99<>"")/(U$4:U$99>=V$1)/(U$4:$U99<=V$2),ROW(INDIRECT("1:"&COUNTIFS(U:U,">="&V$1,U:U,"<="&V$2)))),INT((ROW(A1)-1)/4)+1),"")
Or, this shorter :
=IFERROR(INDEX(AGGREGATE(14,6,U$4:U$99/(U$4:U$99<>"")/(U$4:U$99>=V$1)/(U$4:$U99<=V$2),ROW($1:$99)),INT((ROW(A1)-1)/4)+1),"")

For Loop for Formula that Changes Cell References

I am trying to perform ratio analysis for a collection of financial statements, each of which are contained in a separate excel worksheet. The layout and format of each sheet is exactly the same. See below.
Financial Statement Sheet
For the ratio analysis section I have a separate worksheet where I want to make an array of the computed ratios. See below.
Ratio Analysis Sheet
Unfortunately, I really don’t want to click through each worksheet to create these formulas and would rather write a script with a FOR loop. Since I need to find a ratio for every year of the financial statement the formula itself will need to continuously shift columns to derive a ratio for every year.
This is where I’m stuck. I’m not sure how to loop through every cell of my ratio summary array and use a formula that also changes for each year of the financial statement. I’m thinking I need to make a nested for loop, but I’m really not sure how to attempt the script.
Can anyone do me a huge favor and suggest how I might even start planning this out?
My VBA Developer Console
Here's what I have started, but I need more to figure this out. I don't think my formula will shift columns with this script, and I need help putting the computed values into the array on the ratio analysis sheet.
Sub Current_Ratio()
Dim Current_Ratio As Integer
Dim FirstYear As Long, LastYear As Long
FirstYear = 2015
LastYear = 2019
For i = 1 To Worksheets.Count
If Worksheets(i).Name Like "*Balance Sheet*" Then
For y = FirstYear To LastYear
Current_Ratio = Worksheets(i).Range("F21").Value / Worksheets(i).Range("F51").Value
'need line to place the computed current ratios into range B3:B37 on sheet17(Ratio Analysis)
Next y
End If
Next i
End Sub
Are you open to a formula solution rather than VBA? Here's how I would try it first. I say "try it" because the INDIRECT() function is slow and if you have too many formulas you might not like the performance. But I wouldn't make that judgement until I tried it.
I have a sheet named Company 1 Balance Sheet and in B21:D21 I have 10, 15, and 20 respectively. In B51:D51 I have 20. I also have a sheet named Company 2 Balance Sheet that has the same numerators but 30 as the denominator.
Here is the formula in C2
=INDIRECT("'"&A2&" Balance Sheet'!"&CHAR(66+VALUE(SUBSTITUTE(SUBSTITUTE(B2,"T-",""),"yr","")))&"21")/INDIRECT("'"&A2&" Balance Sheet'!"&CHAR(66+VALUE(SUBSTITUTE(SUBSTITUTE(B2,"T-",""),"yr","")))&"51")
I started by pointing and clicking to build this formula
='Company 1 Balance Sheet'!B21/'Company 1 Balance Sheet'!B51
Then I used INDIRECT to build that formula as a string so I could change the inputs. Let's take just the numerator portion because it works the same for both. My company is in column A, so I can start by replacing that part of the formula
=INDIRECT("'"&A2&" Balance Sheet'!B21")
The Balance Sheet portion of the name will be consistent, so I'll leave that. I'll need to change the B to refer to the proper year. I'll start by making that variable. The letter B is 66 in the ASCII character set.
=INDIRECT("'"&A2&" Balance Sheet'!"&CHAR(66)&"21")
Now I can add whatever year I want to 66 to increment that. My year is in column B, but it has a lot of crud around it. First I need to isolate the numeric portion
=SUBSTITUTE(SUBSTITUTE(B2,"T-",""),"yr","")
That gets rid of the stuff around the number. Then I use VALUE to turn it into a number. I can add that number to 66 so that T-1yr refers to 67 which is C.
And that's it. It's a little painful to set up, but once it's done, you just copy it down. Note the Div/0 errors means you don't have data for that year. Once you're formulas are working the way you want, wrap it in an IFERROR() function to hide those.
In your example, the company name is not repeated on every row. That doesn't work well for this method, but you can have a column where the company is repeated a simply hide that column if your particular presentation is important.
Other things you can with hidden columns: Put in the sheet's name if you don't consistent sheet names or if you just want the formula to be a little easier to read. You could also put the 21 and 51 in hidden columns and refer to those in your indirect function.

How to look through a sheet and find a value, get the column, and then count how many times a value appears in that column

I am working with data that is sent to me. The sheets always contain the same headers though they aren't really headers because it doesn't come in table form, but the columns change every pull so it is never in the same column so I can't do the Index Match like I'm used to. I need to get this to work without converting the data to a table because others that use this don't know how to do that. Is there a way to search the sheet to find the cell containing the value, capture that column address, and then count how many times the column contains a letter?
I have a front excel page that keeps account of how many times something happens. Currently I use this formula =COUNTIF('UDO '!AJ:AJ,"Y"). It works the only thing is that I can't set it up as an array because the column isn't always AJ, so I'm always having to change it manually and I'd like to automate it. So I want to be able to search the sheet that contains the information for the text value example: "Review Required FY*" and get the column that contains this (it should be a unique value) then I want to look down that column and countif it has a "Y" or "y" marked in the cell. The sheets are always varying in length and column numbers. I thought about using an HLookUp but I can't get it to work. I also could not get Index Match to work, because I never know how much data or the column order the Audit tab will be in or have.
So on the Main tab I have a cell that counts how many files I have to audit I want to go to Audit tab, look for "Review Required FY*", capture that column and count how many times "Y" or "y" are there. I'd like to be able to set this up to do it all by itself.
I currently do not have any code because I can't find anything that works.
Using VBA
Option Explicit
Sub Looper()
Dim ws As Worksheet, Found As Range, LR As Long
For Each ws In Worksheets
Set Found = ws.Cells.Find("Review Required FY*")
If Not Found Is Nothing Then
LR = ws.Cells(ws.Rows.Count, Found.Column).End(xlUp).Row
MsgBox Application.WorksheetFunction.CountIf(ws.Range(ws.Cells(1, Found.Column), ws.Cells(LR, Found.Column)), "Y")
End If
Set Found = Nothing
Next ws
End Sub
Assuming the header only appears once, you can find out what row your header is in you can use an array formula like this (apply using Ctrl+Shift+Enter):
=MAX(ROW(A1:A10)*COUNTIF(OFFSET(A1:Z1,ROW(A1:A10)-1,0),"Review Required FY*"))
(looks in the first 10 rows across A:Z)
You can feed the result of that into a lookup to find the column number.
EDIT - something like this:
The first formula needs to be entered using Ctrl+Shift+Enter but the other 2 do not.
The 1000 in the last formula is a best guess at how much data there might be below your header - no problem setting that much larger to be on the safe side, as long as you don't try to count past the end of the sheet.

SPREADSHEETS: Random item from range that matches criteria

I'm making a spreadsheet that will (hopefully) select a random item from a given range where that selected item meets a given criteria.
See the table in the example below. I would like it so that the user can input that they want a cheap place to eat in 'Place C'. (This part I can do fine, it's the next part that I would like help with.) Then I want the spreadsheet to look at this and find a suitable location that meets the needs of the user. Note that in the example there are 3 suitable locations, so I would also like the computer to randomly select one of these. So, to finish, I would like a program that finds a suitable location from the list and if there are more than one, it needs to pick one of these at random.
Thanks.
Also, it has to use just the built-in functions, so no VBA or app scripts.
You can add a column D and use =rand() to generate a random number (drag down you can hide this column). Then create a data validation drop down list on E2 to select Cheap, Moderate, or Expensive. Then enter this query in F2:
=query(A2:D,"Select B where C = '"& E2 &"' order by D limit 1")
This will give you a random pick. Here is a shared example you can copy and try.
https://docs.google.com/spreadsheets/d/189zTNh-c2hotmpUvVSM_UyeVxIfFsM_bs2lZBBSx6ts/edit?usp=sharing

Excel: Dependent Dropdown Lists on Dynamic Content

I've imported a list of clients and their websites from the Google Analytics (GA) API in the following format:
Account Profile
Client 1 www.client1.com
Client 1 sub.client1.com
Client 1 tst.client1.com
Client 2 www.client2.com
Client 3 www.client3.com
Client 3 sub.client3.com
What I need is a dropdown list with the unique accounts names and then a second dropdown list with the dependent profiles of the chosen account. Something that looks like this:
Account Profile
Client 1 www.client1.com
sub.client1.com
tst.client1.com
We add accounts and profiles to GA all the time, so the list will need to be refreshed every time we run the report.
How would I go about doing this?
As long as you have this list sorted by Account, you can use a mixture of Offset CountA to give you all the ranges you need.
Steps would be:
a. Get unique values from Account column (i'm using VBA for this step but you could use Frequency formula to mash this too -- I'd avoid it if you can use VBA for this). Something along the lines:
Sub FindUniqueValues(SourceRange As Range, TargetCell As Range)
SourceRange.AdvancedFilter xlFilterCopy, , TargetCell, True
End Sub
(I've called this from my worksheet_change event for ease but if you are using vba to pull G.A. data, just integrate into that)
b. Feed this to Named Range (Say AccountsRange) that has the forumla =$D$2:INDEX($D$2:$D$5000,COUNTA($D$2:$D$5000)) -- This assumes you specified D1 as TargetCell for previous step and unique values won't be more than 4999 (1st value is row title in my case -- Hence starting from D2)
c. Add this Named Range AccountsRange as source for Data Validation List -- Your account combo box is done at this point. I'm going to assume you put this combo box in E2 and I'll build on this to derive the second ComboBox
d. Create a new Named Range say ProfilesRange with formula =INDEX($B$1:$B$5000,MATCH($E$2,$A$1:$A$5000,0),1):INDEX($B$1:$B$5000,COUNTIF($A‌​$1:$A$5000,$E$2)+MATCH($E$2,$A$1:$A$5000,0)-1,1)
Note: if you copy paste from here the above formula will contain a line-break invisible character after COUNTIF($A and excel will complain about invalid formula, just retype $A$1 part of COUNTIF and it should be fine
A2 is the start of Account column of G.A. imported data (A1 being the title and assuming maximum of 4999 data rows here) E2 is the Comboboxed cell from previous AccountsRange dropdown step. -1 in Match step is needed as the offset needs to be 0 for first value row and not 1 which will be returned from Match. Second 1 is column offset (it can be more if you need to hop several columns to get secondary data). CountIf is pretty self explanatory :) This basically gets us the number of cells we need in final range from the starting point.
e. Create your new Data Validation List that uses ProfilesRange as its source and your secondary combo box is done.
Issues that may arise:
When you change Accounts Combobox, Profiles combobox will probably error out as the values in profiles are unlikely to be present in new client. You could either ignore the error (it will fix itself once you select correct value from newly refreshed dropdown or throw a bit more of VBA fairy dust in there to clear the drop down cell when the value changes in E2.
Data Validation List compalains about evaluating to an error when you try to setup ProfilesRange. It is safe to ignore this error and continue. It basically means nothing computable was returned by ProfilesRange (most probably because you haven't selected anything in AccountsRange that actually computes to a ProfilesRange -- of course assuming your actual cell ranges for formulae used here are actually correct for your sheet)
Thanks to osknows for his tip and improvement on forumlae (in comments below): Avoid use of OFFSET its very slow over large ranges and is volatile. =OFFSET($D$2,0,0,COUNTA($D$2:$D$5000) can be replaced with =$D$2:INDEX($D$2:$D$5000,COUNTA($D$2:$D$5000)) for the named range. (this tip has been incorporated into this solution now, so you won't see the original Offset forumlae unless you check version history)

Resources