how to insert a variable for different sentences using vba? - combinedresourcehandler

i am trying to make a verbiage generator for my friend.
as i see. i am having difficulties in placing an information in between sentences..
example:
the choice of sentences in dropdown are:
1. i bought (A1) from (A2) last (A3).
2. i got a (A1) from (A2) last (A3).
3. i will give this (A1) to (A2) this coming (A3)
A1 was the cell where you put the name of the item
A2 was the cell where you put the location
A3 was the cell where you put the date
if i enter BAG on A1, MATKET on A2 and FRIDAY on A3,
whichever sentences i choose.. the variables will appear on their respective position in the sentence.
i saw some files with this kind of functions with a separate worksheet for the source.
it goes something like this..
1 i bought Var_item from Var_location last Var_date.
2. i got a Var_item from Var_location last Var_date.
3. i will give this Var_item to Var_location this coming Var_date.
and whenever i choose a sentence, it will automaticaly replace the Var_xxxx to the information i entered.
can someone please teach me how to do this?
thank you very much!

Related

Excel 365 Function to Count Occurrence of Array List In Original List

I have a list of company names in the sheet "Defects". I built a unique list of those companies in a sheet called "Report" using this function utilizing an array list.
=SORT(UNIQUE(Defects!E:E,,TRUE),,1)
This works great. Since the array is dynamic, it can grow and shrink. I want to do a count of the number of times a single item from the array appears in the "Defects" sheet.
In the "Defects" sheet This is my complete list
E
1 Acme
2 Gadget
3 Widget
4 Acme
5 Widget
6 Widget
This is what I want in the "Report" sheet.
Company Count
1 Acme 2
2 Gadget 1
3 Widget 3
I can't seem to make a function that will take a specific value in the array as an input as a COUNT or COUNTIF function. This function gives me all values of 1.
=COUNT(MATCH(A20,Defects!E:E,0))
A simple COUNTIF gives me an error and turns the formula into text.
=COUNTIF(Defects!E:E,A1))
Any help is appreciated.
Use LET and CHOOSE with COUNTIFS:
=LET(x,SORT(UNIQUE(E1:E6)),CHOOSE({1,2},x,COUNTIFS(E:E,x)))
Or if you really want full column references:
=LET(y,E:E,x,SORT(UNIQUE(FILTER(y,y<>""))),CHOOSE({1,2},x,COUNTIFS(y,x)))
#Scott's answer is obviously the way to go, doing the whole thing in a single formula, but to answer the part of your question that is about how to make Countif look at an array for its criteria rather than a single value:
Suppose you have a working spill formula for the unique values like
=SORT(UNIQUE(FILTER(Defects!E:E,Defects!E:E<>"")))
in A1,
then to reference all of its values as an array in another formula you just have to put a hash on the end of its reference:
=COUNTIF(Defects!E:E,A1#)
See documentation here

Cell array matches common values excludes blank

I have a list of name that are on one sheet and need to find the most common repeat name of that list. The list spans for the entire month. Example:
10/1 James
10/2 Bill
10/3 Fred
10/4 Hank
etc...
On another sheet I have this in-cell array that finds the most common, BUT if the list has blanks, it returns an error. Only when the list is full does it then give you an answer.
{=INDEX('Sept 18'!B$2:B$151,MODE(MATCH('Sept 18'!B$2:B$151,'Sept 18'!B$2:B$151,0)+{0,0})),"")}
Is there a way to make it always show a name and exclude the blanks as it goes?
If there is data in B2 through B11 that may include blanks, then use the array formula:
=INDEX(B2:B21,MODE(IF(B2:B21<>"",MATCH(B2:B21,B2:B21,0))))
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.

Excel - Find a date within a list of arrays

I need to enter the text 'AL' into cell E3 if the date in E2 is a date someone took as annual leave.
Cells A3:B11 list a start date and an end date someone took as annual leave. See below.
I need a way of checking if a date is between (and including) an array of those two dates, for each from in cells A3:B11.
Note: Cell A5 is one day someone took as annual leave and just requires a start date only.
EDIT: I can use the following algorithm for the first row (A3:B3)
=IF(SUMPRODUCT((ROW(INDIRECT(A3&":"&B3))=E3)*1)=1,"AL","")
I am still stuck however on applying for all possible rows
Using your example sheet, in cell E3 use the formula
=IF(AND($E$2>=A3,$E$2<=B3),"AL","-")
You can then apply this down as many rows as you need. If you need to drag it to the right, across columns, then be sure to switch the cell references (i.e. to hit different dates in cell F2, G2, H2, etc you would use (=IF(AND($F$2>=A3,$F$2<=B3),"AL","-")
The only issue with this method is that you'll need to fill in the End Date for leaves only lasting a day. So just copy that 7/7/2017 over into column B.
P.S. if you actually meant "Array" in the official excel array formula sense, then the solution is different.
I believe I've found a solution with the help of Hoejanson.
=IF(SUMPRODUCT(((A3:A11<=E3)*1),((B3:B11>=E3)*1))=1,"AL","")
It will mean ensuring that both start and end dates are filled for when there is just one day so cell B5 would have to equal 07/07/2018 for this to work.
EDIT: Found a way to allow just a date in the start column to be added.
=IF(SUMPRODUCT((A3:A11<=E3*B3:B11>=E3)+(A3:A11=E3*B3:B11=""))=1,"AL","")
What this is saying is if column A's dates are less than the value in E3, AND column C's date are larger than evaluate true or false. Then the + means 'OR', where column A's dates are equal to E3 AND the corresponding rows in column C are empty. Hope this helps anyone searching a similar answer.

Spreadsheet Array Formula Tweak

Trying to tweak this array formula
=INDEX(D26:W26,MATCH(MAX(COUNTIF(D26:W26,D26:W26)), COUNTIF(D26:W26,D26:W26),0)) & " Winner"
It works and returns AAA Winner
It is for a contest - This counts name entries in each cell and returns which person has the most votes in the range.
What I would like it to do is to put the text Winner first then AAA.
Also, this does not handle if there is a tie in which I would like it to say it is a tie and between who so - Tie Between AAA and BBB. Right now, if there is a tie, it simply lists the very first one...
Hope that makes sense.
Thank you in advance.
just switch it to:
="Winner " & INDEX(D26:W26,MATCH(MAX(COUNTIF(D26:W26,D26:W26)), COUNTIF(D26:W26,D26:W26),0))
But for the Tie-Part it gets hard (you would need to check everything against each other... better just make a new small table which holds each participant and then the value (with countif) which then can be sorted...

Business Objects: Identifying cells with multiple words

I'm currently using (SAP) Business Objects to build a report.
I want to be able to identify rows where a person has both their first and middle name in the same cell.
For example: Cell A1 = "JOHN" Cell B1 = "THOMAS FREDRIC"
What I want to be able to do is only show the cells that include two names in one, e.g Cell B1.
Any advice would be much appreciated!
Build yourself a variable, something like the following should do,
=Pos(Trim([First Names]); " ")
It Trim(s) any leading and trailing spaces from your First Names column and then returns the Pos(ition) of the first space it finds in the column. So any result other than 0 indicates two or more names in the column. Once you can identify the rows you're after there are a number of options (which I can't currently remember the details of) open to you.

Resources