Find Function Where Search Criteria Isn't Exact Match For Cell Contents
Dec 19, 2011
I am new to VBA and am having difficulties in getting a find function to successfully locate search criteria within cell. When the search criteria matches exactly that of the cell contents then the code works; however should the search criteria only form part of the total cell contents (such as a seach for "the" in a cell containing "the cat sat on the mat") the code doesn't recognise it.
Essentially, I need the code to search a range for the required string and if found within a cell activate that cell and populate a combobox with the full cell contents of the activecell.offset(0,-2).
The relevant section of code attached below:
Dim role_count as range
Dim role as string
If Application.WorksheetFunction.CountIf(Range("Role_Count"), Role) 0 Then
Selection.Find(What:=Role, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
I need to search for an exact match within a cell & i am unsure of how to go abt it. Eg ) Cell A1 contains "Emea West,Emea East,Emea". I want to search for the term "Emea" in the contents of the Cell A1. I cant use Find() as using "=FIND("Emea",A6)" returns 1 ... But i want an exact match i.e "Emea" only which in this case should be 21. The Exact() works well if Cell A1 had a single value ...I guess I would need to use some array function here which will parse through contents of the cell , but am not sure on how to go about
I have a workbook with many many sheets in it. The first sheet contains a single column with about 10,000 different values. I'd like to use each of these as search criteria against ALL data in the other sheets (of which there are a good 50 or so). If matches are found (they don't have to be exact case), then I'd like two things to happen:
1. The rows containing the matched search criteria in the first sheet are highlighted.
2. In the cells adjacent to the search criteria in the first sheet, hyperlinks to the matched data are created and named after the sheet upon which this matched data appears.
I've attached a sample file to this post with ideal sample 'answers' to queries made of the first 2 terms.
It works, unless there is a column before the "Categories" column that has the word "Categories" somewhere in its text. So basically if there is a column that has "Unit Categories" it finds that column when I really want it to find a column that has exactly "Categories" as the text and nothing else (but I don't want it to be case sensitive).
Let us say I have the following text in Cell A1. "There is a fault in the cal cycle.Need to update the records." And in cell A2 I have the following text. "Called for backup assistance. There is an issue with numbers." I cells B1 & B2 I need a particular formula which searches for the substring "cal" exactly and returns true if present. In cell A1, we have "cal" in the text. So it should return true for me in cell B1.
However in cell B2 I need false to be returned even though I have "Called" inside the text. I need true to be shown only for those cells where we have the exact text "cal" and no text characters in front or back of it.
This section of code I am working on requires me to find an exact text (I tried lookat:=xlWhole, but I can't get it to work right). The problem being is when it searches for Q1, Q10 is an acceptable answer ans so on. I need to get the 4th occurrence, but my research into Nth occurrence stuff is confusing.
The search is in a single column.
With Workbooks("FY12-Q3 Data Tables.xlsx").Sheets("PBA Crosstabs").Columns(1) Set c = .Find(rCell, LookIn:=xlValues, lookat:=xlWhole) Set c = .Find(rCell, After:=c, lookat:=xlWhole) Set c = .Find(rCell, After:=c, lookat:=xlWhole) Set c = .Find(rCell, After:=c, lookat:=xlWhole) End With
I am having a slight VBA issue I need a little help with. I have created a catalog of books in Column A. As each new letter is reached there is a new heading. For example:
Cell A1 : A Cell A2 : Book beginning with A #1 Cell A2 : Book beginning with A #2 Cell A3 : Book beginning with A #3 Cell A4: B Cell A5 : Book beginning with B #1 Cell A6 : Book beginning with B #2 Cell A7 : Book beginning with B #3 Cell A8 : C etc.
What I am looking to do is create a macro for each letter so that if I went to the "B" macro it would make the active cell A4. However the list of books will grow as my library does, so the macros have to find the letter rather than go to a predefined cell.
The code I have so far is (this example is for the letter B):
Sub B() Columns("A:A").Select Selection.Find(What:="B", After:=ActiveCell, _ LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False, _ SearchFormat:=False).Activate ActiveCell.Select End Sub
However this code finds the first time the letter B is used in a word, not the cell that only has the letter B in it. Also I need to make sure that if the active cell when the macro is run is below the letter that it needs to find that it will still find it. I'm not sure if my current code would do that or not.
In the four rows of text below I'm trying to match each gas stick to its corresponding gasline.
I think I can count over to "GAS STICK" and get the number. <15> From that point I can count over to "," (comma) and get that number. <26> So the gas stick will be between the first number and one less than the second number. <GAS STICK 1>
I need completing this code to place a the line or stick number in a cell B of the same row. Column A would have the description and column B of the same row would either be "1" or "11" respectively. Column C would be the shortened description (GAS STICK 1).
Using the dcount function it appears that the criteria is not exact. I have typed in ="IP" but instead of getting only IP. I'm getting cells beginning with IP, eg IPp and IPe. When I use countif I don't get this problem.
If Cells(3, k).Value = "Actuals" Then DesActualColumn = Cells(3, k).Column End If nice and simple, and works fine until it cannot find "Actuals" in the cell because someone has put a tab ahead of it, for example. Can anyone tell me how I can use a 'LIKE' and put wildcards
I have a file with duplicate names of test id's in col a. In col b I have single test id's and col c I have test names. I need to search col a for exact match of test id in col b and if it is there then put the name of test in col c into col d.
See attached document. Basically I need to know the name associated with the ID in column B.
On sheet1, I have numbers and names. These names are also contained in Comments on sheet2, and i would like a function in Column M that matches the numbers with the names in the comments. Cell M1 I have manually filled for demonstration purposes.
Can this be done with a function or is this a VBA task?
I am having such a difficult time creating a macro that will reduce the 5+hours I have to spend each week manually copying & pasting all of this data. I making an IMMENSE difference in this worker bee's life!
I have a workbook with two sheets (Sheet1 & Sheet2). Sheet1 has license #'s in column A and the state that the license belongs to in column B like this:
COLUMN ACOLUMN B11111Alaska11112Alabama11113Arkansas11114Arkansas Sheet2 has three columns. Column A has the license #'s, column B has the state that the license belongs to and Columns C shows a line-of-authority tied to that license #.
I'm trying to write a macro that will compare the license # and state in Sheet1 to the license # and state in Sheet2. If it matches, append the contents of Column C to the corresponding row in Sheet1.
Here's the thing...Sheet2 contains the entries for all licenses in the company (so this table is HUGE). And there are multiple entries for each state license # (notice how there's two entries above for AK license # 11111 - one for the Property line and one for the Casualty line.
After my macro is run, I want Sheet1 to show all the lines-of-authority on a single line. So if I ran my macro on the above example, after it's run I would have this in Sheet1:
COLUMN ACOLUMN BCOLUMN C11111AlaskaProperty Casualty11112AlabamaProperty Casualty11113 ArkansasLife Health11114ArkansasLife Health
I am having some trouble getting a formula to work. I am building a report that pulls figures from a pivot table in another workbook. I am using a vlookup with match function to get the column index to find the relevant data I want. Where I need to add two columns together I am using sum, with the vlookup & match formulas nested in them e.g.:
Where: F13 = Employee number Column C on the pivot 156 workbook is where the employee number is based. The Match formula is then getting the column index from the column headings of the pivot table ie. "FAID"
This in itself works fine, as long as it finds a match in the column headings. This is where i get the error as in the above function "COMD" is not in the pivot table. However I need to keep it included as it may appear on a future pivot table. Is there a way of getting the sum function to complete even though later in the formula it can't complete the vlookup? So it will ignore it, or assume the value is zero if it can't find it? The formula probably needs to do this for all the vlookups as some headings may drop off in future pivot tables.
I have an 'Update' Module that search the value of the Userform1.txt_sc.Value in Column B, but I want to search to 2 criteria, how can i amend the below code to search for 2 criteria ( userform1.txt_sc.value & userform1.txt_linenum.value )
Date Open High Low Close Volume Adj Close Semi-Annual Yield Theoretical Bond Price Index Coupon Total Value Peaks Troughs
The Relevant columns would be "Date" column A cell 1, "Total Value" column L cell 1, "Peaks" column M cell 1, and "Troughs" column N cell 1. What I basically want to do, in the next column, column O, is this: If cell N# = "Trough" find the previous M cell = "Peak" and take the L cell in that "Peak" row and subtract the L cell in the Trough row from it (like =(L4-L9)/L4)). Then in column P, if the percentage drop was 5% or greater, I want to find the days between the trough we are looking at, in cell n10, and the NEXT Peak, cell M11, using the corresponding dates in Column A.
I have a spreadsheet that contains data for a fiscal year broken out by month and quarter. I want the formula to return the data from that month and use whatever the latest quarter is. For example in the data below:
If it has only pulled data only thru Q1 it would return Q1 for Jan-Mar, however once I have Q2 data I would want the formula to return Q2 for the months of Jan-Mar.
2013Thru Q1STOLISTOLIJan-2013STOLI BASE 2013Thru Q1STOLISTOLIFeb-2013STOLI BASE 2013Thru Q1STOLISTOLIMar-2013STOLI BASE 2013Thru Q2STOLISTOLIApr-2013STOLI BASE 2013Thru Q2STOLISTOLIMay-2013STOLI BASE 2013Thru Q2STOLISTOLIJun-2013STOLI BASE 2013Thru Q3STOLISTOLIJul-2013STOLI BASE 2013Thru Q3STOLISTOLIAug-2013STOLI BASE 2013Thru Q3STOLISTOLISep-2013STOLI BASE 2013Thru Q4STOLISTOLIOct-2013STOLI BASE 2013Thru Q4STOLISTOLINov-2013STOLI BASE 2013Thru Q4STOLISTOLIDec-2013STOLI BASE 2013Thru Q4STOLISTOLIDec-2013STOLI BASE 2014Thru Q1STOLISTOLIJan-2014STOLI BASE
I am very new withe macro I recieve every day a CSV file from our supplier withe a list of the products that got updated withe new price, stock count, product ID etc.
I have my own worksheet with the product ID that we use, and I want to finde the exact match to my product ID in that CSV file and delete all other that don't match.
But i need them get deletede by rows thos product ID that dosen't match to my workbook.
I tried with this, so it could set an X in front of my match then i could filter and copy it to my workbook but it dosen't work: Because the same product ID is sometime in 100 rows and the X come only in front of one of them.
so with some macro. I need to have every row deleted that don't match to my list of product ID.
I went through all the forums but confused a little. In the work sheet I want Excel to find an exact word such as letter "a" in all over the work sheet (not a column name) and paste it to the destination work sheet. I am attaching an example file, can some help me to solve the problem.
which works fine. now the problem is that when i'm searching for lets say "ABCD" in one of the workbooks, if there is an entry "ABCD " (with a space at the end) it says that the entry doesn't exist. is there any way of correcting it such that it would always neglect the space at the end if it exists? i tried using -1 instead of 0 and it messes up, so i'm not sure what to do.
Attached is a sample workbook, but essentially what I'm looking to do is automate the process of searching through a data set where the value of interest (in this case, names) often has multiple entries, with different values attached to each instance.
I would like to be able to get a list of all values in a given column that match a specific name in another column.
Currently I'm using a basic INDEX/MATCH search just to see whether the data exists at all, but that's only half of what I have to do here, and I'm totally stumped on how to get a comprehensive list of all matches.
For reference, if you look at the sample, what I need is a list of all values in the "CPT" column that match the name searched for in the first column.
The actual data set size is at most 3-400 entries, if that makes a difference in how to approach this.
Column J is the date opened. Column T is the date closed. Of course, column T will have no date if still open. Column K and O may or may not have text. Column AF6 has a date, mm/dd/yyyy, that is entered/changed depending on the search.
What I need is a formula in AF8 that will look at the date entered in AF6 and find a match in columns J and T. Then it will look to see if there is text in K and O. If so, populate AF8 with that text.