Trouble recognizing ' with VBA

mtterry

New Member
Joined
Aug 9, 2016
Messages
45
If the contents of a cell start with ', I'm trying to change them using VBA - the first step being to delete the single quotation; however, I'm having trouble getting VBA to recognize the single quotation in the below If statement:

If Left(cel.Value, 1) = "'" Then ..... - I tired cel.text as well and same issue. All of the cells that do start with a single quotation are followed by a 0 - and if I use this:

If Left(cel.Value, 1) = "0" Then...... it will recognize every cell that starts with either a ' or a 0.

I'm not sure how I can get VBA to pick up the ', any help would be appreciated.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
66,012
Office Version
  1. 365
Platform
  1. Windows
Try
Code:
If activecell.PrefixCharacter = Chr(39) Then MsgBox "yes"
 
Last edited:

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
11,685
When a cell has a ' at the start, it's really not part of the value of the cell. It's just an indicator to Excel that the contents of the cell is text. That's why your Left() constructions don't find it. If you actually want a ' as part of the value, you'd have to do something like:

="'This is a test"

Your Left() will pick it up in this case.
 
Last edited:

mtterry

New Member
Joined
Aug 9, 2016
Messages
45
This worked great to identify ' - but now I'm struggling to remove it. It appears from the treatment that I likely don't need to remove it now, but I'm curious to know if/how that can be accomplished?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,826
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You'd need to clear the formatting of the cell.
 

Forum statistics

Threads
1,148,294
Messages
5,745,944
Members
423,985
Latest member
sayed manzar

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
Top