Excel: Highlighting duplicates with exact matches - vba

I've got two columns of data, and I would like to use conditional highlighting to find the EXACT matches in both columns. However, using a formula like this one turns up a lot of incorrect matches:
=MATCH(A1,B:B,0)>0
There are a lot of partial matches, so cells are highlighted that I don't want. What I want is the equivalent of the "Match Entire Cell Contents" checkbox in the Find & Replace dialog.
To make this clear, it seems Excel will do partial matches - here is the Find & Replace dialog without "Match Entire Cell Contents" checked, with a sample search for all matches:
Search for all matches, any match
Vs. the dialog with the checkbox ticked and the results:
Search for all matches, match entire cell
But this only applies to find & replace. How can I update the formula above to work the same way, so that only exact matches to what's in a cell are highlighted?

=NOT(ISERROR(MATCH(A1,B:B,0)))
Regular use of MATCH() - without wildcards - doesn't do partial matches, and MATCH returns an error if there's no hit, not zero

This isnt quite what is being asked, but this was helpful to me:
To find duplicate records, use Excel's easy-to-use Filter feature as follows:
Select any cell inside the recordset.
From the Data menu, choose Filter and then select Advanced Filter to open the Advanced Filter dialog box.
Select Copy To Another Location in the Action section.
Enter a copy range in the Copy To control.
Check Unique Records Only and click OK.
There's more about conditional formatting on this site:
https://www.techrepublic.com/blog/windows-and-office/how-to-find-duplicates-in-excel-245163/

Related

VBA Autofilter for Criteria IsLetter / any text

I have a column that I need to filter as part of a sub routine that is free text. I need to filter out all of the cells that contain text of any sort. I am using the vba code
With rng
.AutoFilter Field:=1, Criteria:= "cannot find solution - need [A-Za-z]"
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells (xlCellTypeVisible).Rows.Delete
The code itself works fine, I just can't workout how to set the criteria to any letter of the alphabet
Is there a way to do this??
Thanks for any advice.
You can set the same filter via VBA that you can set within Excel, so you should first try to find a filter setting in Excel that fits your need.
When found, remove the filter and record a macro while setting the filter again - that will show you how to set it using VBA.
In your case, I set a custom filter: Click on the filter button on that column, select either "number filters" or "text filters (displayed depending what Excel guesses is the main data type of that column), and select "custom filter".
There, choose "contains" and enter a ? as search value.
If that fits your need, this is the code in VBA:
.AutoFilter Field:=1, Criteria1:="=*?*", Operator:=xlAnd
If this doesn't fit your need because your filter is even more sophisticated, only idea I have is to create a helper column, write a UDF that returns either True or False depending if the value is to be displayed or not and filter on that helper column instead (you could use regular expressions in that UDF).
Or loop manually over your data and decide in your code which row fits - but be carefull when deleting data, either loop backwards or build a union and delete in one go - plenty of examples for that on SO.

VBA - highlight cells with Absolute references

I have inherited a massive spreadsheet with many sheets, and many formulas that have a lot of absolute references.
These sheets need to be combined into one, is there an easy way to identify absolute references quickly with VBA?
I was thinking of some conditional formatting for cells that contain "$" but that doesn't work.
Alternatively I figured a script could run through each cell and evaluate it's absolute contents, if it identifies a "$" it then formats the cell and moves on to the next.
Thanks for your time :)
You can easily do this with conditional formatting:
Mark all your data
Select "conditional formatting", "New rule"
Select "Use a formula to determine which cells to format"
Enter the formula =FIND("$",FORMULATEXT(A1))>0 (assuming that the first cell you selected is [A1]. FORMULATEXT will look for the text of the formula of a cell and FIND will search for a $ within that formula.
Do not forget to set the formatting, e.g. a fill color
A simple solution for even basic users:
Ctrl+F (search),
enter search parameter "$" (in this case),
Ensure the drop boxes have selected:
Within: Sheet
Search: By Rows
Look in: Formulas
Uncheck the "Match entire cell contents" checkbox,
click "Find all"
In the list that appears within the search window,
select all of the entries, it will select the entire search group.
Apply formatting to the selection to highlight these cells.

Make small changes to multiple functions without affecting cell reference

What is the best way to change ">" to ">=" in 100+ formulas such as:
=IF(INDEX($B$2:$B$46,MATCH(A3,$D$2:$D$46,0))**>**$A$2),"1","0")
=IF(INDEX($B$2:$B$46,MATCH(A3,$D$2:$D$46,0))**>**$B$2),"1","0")
=IF(INDEX($B$2:$B$46,MATCH(A3,$D$2:$D$46,0))**>**$C$2),"1","0")
Would I need some VBA code?
I would suggest one more idea if you are not comfortable doing the find and replace in excel.
Press the key combination Ctrl+` (BackQuote symbol)
Now you will have all the formulas visible in the cells.
Copy the range or columns in which you need to modify the formula
Paste it in a .txt file and then do the find and replace
Once it is done copy all the formula and paste it back to the same range.
Press Ctrl+` again and now you have got all the formulas changed as per your need
As long suggested, take a backup of your worksheet before you do these modifications
As Scott_Craner stated, a simple Find/Replace should work.
Save a version of your data in case you misjudged where the search subject is in your data.
Highlight the cells with the formulas you wish to change.
Press Ctrl and the F keys (or click on "Find&Select" in the Home tab in the "Editing" group and select Replace from the drop-down)
In the Find and Replace dialog box, make sure you are on the Replace tab.
In the "Find what:" box, type ">" without quotes (note, if there are other > symbols in some formulas, you can distinguish these with some repetitive text before and after)
In the "Replace with:" box, type "<" without quotes (note, if you included other text to specify certain instances of ">", make sure you include all the text that should also be replaced)
Hit the "Replace All" button.
Your spreadsheet formulas should now be as you'd like them. If they're not, thank goodness you saved another version first. Find/Replace is very powerful, so make sure to limit the scope by selecting the cells you want searched and being sure that Excel will find only those data you wish to change.
If you are interested in VBA, you could use it here. But Excel already has a powerful, user-friendly tool at your disposal.

VBA script in excel to find and highlight text

I am looking for a VBA script that will help me find certain keywords in a cell and if found highlight the entire row. Below are my requirements:
I have a database of words eg hell, get out, shut up, don't you dare etc. I need a macro to search the data in column "E" of excel and in case any of the cell in column "E" contains any word listed in the database (irrespective of the case of the word upper or lower)the entire row is highlighted. The word can be in the beginning, middle or end of the cell and the macro should be able to find that word and highlight the column.
Seeking help from all VBA masters for this.
You can do this with conditional formatting, instead of VBA.
Conditional formatting works by applying a 'second formula' to a given cell. If the 'second formula' results in TRUE, then special formatting conditions can be applied.
EXAMPLE CONDITIONAL FORMATTING
For example, if you have a single column of Data, A:A, and you want to check if that column has the exact string "hello world", you could add a conditional format [Home ribbon, Styles section, Conditional Formatting] that turns a cell yellow with this formula:
=$A1="hello world"
This will only result in TRUE if the cell in column A at that row equals exactly "hello world" [note that Column A has an absolute-reference $, and row 1 does not, so row 1 is relative to the position of the cell in the condiitonal format rule].
To check to see if any row in column A includes hellow world, we need to add a SEARCH function, which checks to see if a small search string is inside of a larger string:
=SEARCH("hello world",$A1)>0
Because SEARCH by default returns the first character in a larger string that matches the search term (and if it finds nothing, it returns #N/A), we check to see if our search for "hello world" in column A returns a number.
SEARCHING MULTIPLE COLUMNS
Now, to see if ANY column, say from A-D, includes "hello world", we concatenate each value of each column so that it gives us a single string, which we can search through for "hello world", like so:
=SEARCH("hello world",$A1&$B1&$C1&$D1)>0
This will first create a single string, equal to A1 & B1 & C1 & D1 all in a row. Then it will search that newly created string to see if "hello world" is inside it, and return a number value if it is.
ARRAY FORMULA BASICS
Finally, we need to do the tricky part - searching for multiple terms instead of just "hello world". This is called an Array Formula. An array formula works by performing a single operation on multiple cells, and then returning multiple results in an Array. In an Excel sheet, an array formula must be confirmed with CTRL + SHIFT + ENTER (instead of just ENTER), but in conditional formatting, you actually don't need to do anything special - it will recognize an array formula without a special command.
As an example of conditional formatting, see this example, which checks whether any value from A1:A5 = 10, and if it does, it gives us the value in B1:B5:
=IF(A1:A5=10,B1:B5,"")
Remember in Excel on a worksheet, this would be confirmed by pressing CTRL + SHIFT + ENTER. If you do test this, it will give you the following result, assuming A2 = 10 and A5 = 10:
={"";B2;"";"";B5}
This result would actually be hidden, because Excel can't "collapse" an array function on its own. So assume column B had values, and we actually want to sum them together. We would then wrap the Array formula in a SUM function:
=SUM(IF(A1:A5=10,B1:B5,""))
As you can see if you test this, we have actually created our own SUMIF function, using Array formulas instead of the built-in SUMIF.
SEARCHING FOR MULTIPLE TERMS WITH ARRAY FORMULAS
So now we apply these principles to the conditional formatting, to create an array formula which will check our concatenated 'NEW STRING' for any number of provided terms, as follow [Assumes the search terms are typed into cells E1:E10]:
=SUM(SEARCH($E$1:$E$10,$A1&$B1&$C1&$D1)>0)
This formula can be placed as a conditional formatting rule which reaches all of A:D. Set the rule to highlight / change format in whatever way you like.

Open Refine / Google Refine - Remove blank cells in a column

The task is simple to understand, I have a table like this:
And I would like to edit the column "L1_latitud" to collapse (or remove) all the blank cells:
It looks like a simple task but I can't find out a way to deal with it.
Not sure this is a programming question, but if what you show is a single Refine record (you can check by switching from Row mode to Record mode for viewing), you should be able to use "Join multi-valued" cells to collapse all the values into a single string with separators. From there the split(), filter(), join() methods would allow you to filter out the empty values and put the string back together. Finally, "Split multi-valued cells" would split them out into separate cells again.
I sense that you've already done some processing here, so there might be an easier way to do this if you started a step or two earlier in the process.
Create "Facet" -> "Customized facets" -> "Facet by null"
then simply exclude True choice in facet