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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try
Code:
If activecell.PrefixCharacter = Chr(39) Then MsgBox "yes"
 
Last edited:
Upvote 0
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:
Upvote 0
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?
 
Upvote 0
You'd need to clear the formatting of the cell.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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