|
-
Oct 23rd, 2006, 05:19 PM
#1
Thread Starter
Frenzied Member
Comparing 2 cells....
Alright, I know how I would do this in VBA. But, I was curious to see if anyone knew of a formula I could use to compare the values of 2 cells to see how similar they are.
I was unable to find any such function that could be used in formulas, so I will just go ahead and work on my VBA function.
But, I'll check back and see if anyone has anything for this.
Thanks.
-
Oct 23rd, 2006, 05:22 PM
#2
Re: Comparing 2 cells....
Wouldnt it be just an IF comparison?
VB Code:
=IF(A2=A3,"Match","NoMatch")
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 23rd, 2006, 05:27 PM
#3
Thread Starter
Frenzied Member
Re: Comparing 2 cells....
Well, I can do that... But what I need to know is if there are any similarities.... More like if they have any common words.
I can do it easily in VBA, but, just... I am LAZY right now.
So say you take:
Muffins are very good
And
Muffins are not very good at all.
Compare them and, well, figure out how much they have in common. But, as I said... I seriously doubt there is a way to do this with formulas......
-
Oct 23rd, 2006, 05:37 PM
#4
Re: Comparing 2 cells....
Oh more like a fuzzy match comparison. Hmm, nope nothing built in for that.
Probably just split the cell into an array split on the space char?
Then loop comparing the target cell with an Instr function comparison.
Or maybe a .Find method passing the array element.
I'm feeling lazy too. Was out at a clients site today. Time for a nap
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 23rd, 2006, 06:03 PM
#5
Thread Starter
Frenzied Member
Re: Comparing 2 cells....
Haha, good reply, that's exactly what I am doing and it is working great thus far. Now time for some statistical crap and we're ready!
Thanks a lot.
-
Oct 23rd, 2006, 10:36 PM
#6
Addicted Member
Re: Comparing 2 cells....
It's funny you guys mention this, I just gave someone some code exactly how RobDog described....
Say you have your main values on sheet "Blad1" in column B and your new (or comparison) values on sheet "Blad2" in Column B.....
I know you said you got it working, but just to compare:
VB Code:
Option Explicit
Sub CompareStrings()
If TypeName(Selection) <> "Range" Then Exit Sub
Dim wsBlad1 As Excel.Worksheet, wsBlad2 As Excel.Worksheet
Dim cell As Excel.Range, cellMain As Excel.Range
Dim rngBlad1 As Excel.Range, rngBlad2 As Excel.Range
Dim strMain As String, strCompare As String
Dim SplitMain As Variant, SplitCompare As Variant
Dim i As Long, j As Long, ItemMatch As Long, count As Long
Dim Percents() As Single, StringMain() As String
Dim StringCompare() As String
Dim sPercent As Single
ReDim Percents(0)
ReDim StringMain(0)
ReDim StringCompare(0)
Set wsBlad1 = Worksheets("Blad1")
Set wsBlad2 = Worksheets("Blad2")
Set rngBlad1 = wsBlad1.Range("B2:B" & wsBlad1.Cells(Rows.count, "B").End(xlUp).Row)
Set rngBlad2 = wsBlad2.Range("B2:B" & wsBlad2.Cells(Rows.count, "B").End(xlUp).Row)
For Each cell In rngBlad2
SplitCompare = Split(WorksheetFunction.Trim(cell.Text), " ")
For Each cellMain In rngBlad1
SplitMain = Split(WorksheetFunction.Trim(cellMain.Text), " ")
ItemMatch = 0
For i = LBound(SplitCompare) To UBound(SplitCompare)
For j = LBound(SplitMain) To UBound(SplitMain)
If UCase(SplitCompare(i)) = UCase(SplitMain(j)) Then
ItemMatch = ItemMatch + 1
Exit For
End If
Next
Next
sPercent = Round(((ItemMatch) / (UBound(SplitMain) + 1)) * 100, 2)
'Exit Sub
If sPercent > 0 Then
ReDim Preserve Percents(0 To count)
ReDim Preserve StringMain(0 To count)
ReDim Preserve StringCompare(0 To count)
Percents(count) = sPercent
StringMain(count) = cellMain.Text
StringCompare(count) = cell.Text
count = count + 1
End If
If sPercent = 100 Then
Exit For 'May not want this...but unsure
End If
Next cellMain
Next cell
With Sheets("Blad3")
.Cells.Clear
.Range("A1") = "Percent"
.Range("B1") = "Main Database Text"
.Range("C1") = "New data text"
.Range("A2:A" & count + 1).Value = WorksheetFunction.Transpose(Percents)
.Range("B2:B" & count + 1).Value = WorksheetFunction.Transpose(StringMain)
.Range("C2:C" & count + 1).Value = WorksheetFunction.Transpose(StringCompare)
End With
End Sub
-
Oct 24th, 2006, 01:29 PM
#7
Thread Starter
Frenzied Member
Re: Comparing 2 cells....
That is essentially what I did... A little less code however. It's simple and works nicely.
Thanks for all the replies.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|