Leading Apostrophe

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I'm comparing database against an excel worksheet range. The range value ignores the Leading Apostrophe which makes the compare fail as the db does include it.
Is there any method for Excel to detect it's presence ?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi ABB. This probably won't help, but if the values are actual values, a formula like =IF(ISTEXT(A1),VALUE(A1),A1) would remove leading apostrophes.
 
Upvote 0
What is that you want to know that is different from the last time you asked this question a few years ago ?
Identify cells with leading apostrophe via VBA
You seemed to indicate that you found this helpful.
Searching for Leading Apostrophes

Essentially the only way to identify it was in VBA to use (taking the Activecell as a sample)
VBA Code:
Debug.Print ActiveCell.PrefixCharacter

Is it an option to go the other way and to remove the "'" from the db record (if you are putting it into a recordset or array first) before doing the comparison ?
 
Upvote 0
Solution
Thanks, I'll chck out .PrefixCharacter. Could be handy - didn't know about that or had forgotten. YesI was detecting it from the db record but handy to have an alternative.
 
Upvote 0
The prefix method is the only way I can find of detecting the leading Apostrophe, so for a match like you are after you would be looking at doing something like this:

VBA Code:
Sub CompareText()

    Dim dbText As String
    Dim cellText As String
    Dim rCell As Range
    
    dbText = "'Text String"
    Set rCell = ActiveCell
        
    cellText = rCell.Value
    If rCell.PrefixCharacter = "'" Then
        cellText = "'" & cellText
    End If

    If cellText = dbText Then
        MsgBox "Exact Match"
    Else
        MsgBox "Difference"
    End If

End Sub
 
Upvote 0
Thanks Alex all sorted. Looks like I did know this but had forgotten it.
 
Upvote 0

Forum statistics

Threads
1,216,089
Messages
6,128,760
Members
449,466
Latest member
Peter Juhnke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top