I ve just used Vlookup Function.
Seems to work fine, but in some cases it doesn't return the very closest value.
Example : If your lookup value is 3.9, it will return 3 instead of 4. Any way to fix that?
According to MS Documentation on VLookUp function, you can set the 4th parameter to "TRUE if you want an approximate match".
In my opinion, the term "approximate" doesnt' mean "closest number", since you can also look up for string or dates.
To solve your problem, create a small function that loop through your data in B column, compare your value in A3 to values in Bx and save the value with the smallest difference.
First of all I would like to tell you that I have just basics with VBA or Visual Basic. So probably there will be better solution in VBA, but I was unable to find a way. That's why that my attempt is so crude. Also my english can be somewhat broken sometimes. I'm sorry for that.
Below you can find screenshots from my excel sheet. You can notice functions are in czech language. You can find translation below.
Screenshot with actual results:
Screenshot with actual functions:
Translated functions:
AA =COUNTIFS(A:A;X2;D:D;D129)
AB =IF(AA129=1;CELL("address";INDEX(D:D;MATCH(D129;D:D;0)));"NULL")
AC =IF(AA129=1;REPLACE(AB129;2;1;"M");"NULL")
AD =IF(AA129=1;CONCATENATE("=IF(";"""";M129;"""";"=";AC129;";1;0)");"NULL")
AF =ISNUMBER(AE129)
AG =IF(AF129=TRUE;CONCATENATE(AE129);0)
Description:
Every day someone downloads .csv files from JIRA and uploads it to excel. That csv contains test cases. Column X has the date when this csv was uploaded, Column D has the ID of the test case. Column M has the date of the last change on that test case.
Functions description:
AA: It searches if there is the same test case in previous day. If yes, then result is 1. If no, Result is 0.
AB: Locates the exact cell location of the same test case from previous day.
AC: Serves for translation from ID column (D) to last change column (M).
AD: Composes translated information from AC, so it will create a function, which I would like to use further. That function will compare last change date with the test case from previous day and current day. Result should be 1 or 0 depending on if there was any change.
AF: Checks if AE is number (AE should be the column where I would like to run
that function from AD).
AG: If AF is true, then it copies value from AE. Else it's 0
Problem is:
I can't find a way to trick excel to take the text from AD and use it as function in another cell. Tried to program it in VBA, but failed.
What I need:
Translate result from AD from text to function and then run it in AE.
If there is a more efficient way to program this, I am open to suggestions. But I would like to have an answer for my question as well. I want to know if it's possible because I will make more complicated cases later while I learn to work with VBA.
Thanks for the response.
Trying to place formula:
IF(TEXT(A4,”ddd”)=“Fri”,IF(TEXT(B4-INT(B4),”hh:mm:ss”)>=TEXT(TIME17,0,0 "),”hh:mm:ss”),”flag”," "),IF(TEXT(A4,”ddd”)=“Sat”,”flag”,IF(TEXT(A4,”ddd”)=“Sun”,”flag”,IF(TEXT(A4,”ddd”)=“Mon”,IF(TEXT(B4-INT(B4),”hh:mm:ss”)<=TEXT(TIME("8,30,0"),”hh:mm:ss”),”Flag”,"”)))))
into cell but using CHR(34) instead of " makes it too long in character length. Then tried using defined name and in "refers to:" used the evaluate formula i. e. =evaluate("T1"); T1 had the text version of the formula as above.
Create Date Create Time
03/05/17 07:28 AM
09/05/17 07:32 AM
13/05/17 07:20 AM
16/05/17 04:57 PM
17/05/17 10:17 AM
The spreadsheet contains date in column A and date-time formatted as time in column B. I am working out if the particular line is between the hours of Fri 5pm and Mon 8:30am.
If you just want a shorter formula, you could use
=IF(OR(WEEKDAY(A4,2)>5,AND(WEEKDAY(A4,2)=5,B4>17/24),AND(WEEKDAY(A4,2)=1,B4<8.5/24)),"Flag","")
In VBA, that could be coded as (for instance):
Range("C4").Formula = "=IF(OR(WEEKDAY(A4,2)>5,AND(WEEKDAY(A4,2)=5,B4>17/24),AND(WEEKDAY(A4,2)=1,B4<8.5/24)),""Flag"","""")
The above formulas assume that column B just contains the time, but if it contains the date and time, then you should use:
=IF(OR(WEEKDAY(B4,2)>5,AND(WEEKDAY(B4,2)=5,MOD(B4,1)>17/24),AND(WEEKDAY(B4,2)=1,MOD(B4,1)<8.5/24)),"Flag","")
In VBA, that could be coded as (for instance):
Range("C4").Formula = "=IF(OR(WEEKDAY(B4,2)>5,AND(WEEKDAY(B4,2)=5,MOD(B4,1)>17/24),AND(WEEKDAY(B4,2)=1,MOD(B4,1)<8.5/24)),""Flag"","""")
Correcting your original formula to what I think you intended it to be, would give you VBA code of (for instance):
Range("C4").Formula = "=IF(TEXT(A4,""ddd"")=""Fri"",IF(TEXT(B4-INT(B4),""hh:mm:ss"")>=TEXT(TIME(17,0,0),""hh:mm:ss""),""flag"","" ""),IF(TEXT(A4,""ddd"")=""Sat"",""flag"",IF(TEXT(A4,""ddd"")=""Sun"",""flag"",IF(TEXT(A4,""ddd"")=""Mon"",IF(TEXT(B4-INT(B4),""hh:mm:ss"")<=TEXT(TIME(8,30,0),""hh:mm:ss""),""Flag"","""")))))"
There are several things in that that could easily be simplified, e.g.:
TEXT(TIME(17,0,0),""hh:mm:ss"") could be more simply written as "17:00:00" (it's a fixed time that is going to have a fixed result), and
TEXT(B4-INT(B4),""hh:mm:ss"") could be simplified to TEXT(B4, ""hh:mm:ss"") (the time string is going to be the same whether you calculate it on the specific day, or whether you calculate it on 0 January 1900).
See image for what I have going on
So the red column will at some point, which is different every day, change from 20 to 50. The start cell up top uses that lookup formula to find when this is. So for this example it is 10/11/16 14:37. I want to graph the green and blue columns, starting at that cell time and ending at the end time (which is just a max() of the times to get the end time).
I've looked into offset and name manager but I am really confused on those. Either using VBA or something else to change the graph (on a different sheet) to start at whatever that start time is would be awesome.
You can try the following:
In the column AL set, in each cell, the value to be defined by the following formula
AL1 = IF(AI1<50,0,1)
AL2 and following = IF(AL1=1,1,IF(AI2<50,0,1))
Then define each AM to be AL*AK, and plot AM.
I have one sheet which is comprised of data that was imported from a web page. In a second sheet I have a cell asking for min price and max price which comes from the imported data. The issue is that the data can move to different cells when it's refreshed so my code needs to look for some specific wording to find the prices that I need rather than just directing it to the same cell each time
The info in the imported data sheet which I need to extract from will always be in this string of text which will always be found somewhere between row 15-35 but will move when the website is refreshed. The 1st number (71.00) needs to be extracted to another sheet in a cell asking for min price while the second number (75.00) is the max price. These prices can change so I can just look for those numbers and extract them.
SLAUGHTER BULLS: Yield grade 1-2 1000-1500 lbs
1500-2000 lbs 71.00-75.00.
Could someone please help me with the coding for this macro?
Use the InStrRev function (similar to the LastIndexOf function in .NET) to find the last index of "lbs" in the test string.
lastIndex = InStrRev(testString, "lbs", 1, 1)
Then search from that last index to the end of the string spliting on the -
splitArray = Split(Mid(testString, lastIndex, Len(testString) - lastIndex), "-", 1)
The lowest value will be in splitArray(0) and the upper value will be in splitArray(1) assuming a zero indexed array.