ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Detecting a single quote from a cells value (https://www.excelbanter.com/excel-programming/395174-detecting-single-quote-cells-value.html)

John Keith[_2_]

Detecting a single quote from a cells value
 
I need to know when the input data contains the prefixed single quote to
force the data to be treated like text.

I am showing SQL table data that contains scripting commands. The presence
of a single tick indicates that this script command is a comment. I want to
process through my script commands and turn the font to green when the script
command being displayed in a cell is a comment.

How do I detect the presence of a prefixed single quote in a cell from VBA?
Left$(cell.value, 1) = "'" is never true because excel strips this
character from the value (although it is still shown in the formula bar)
Neither does the cell.formula show the prefixed single quote (this seems
like it should though)

Is my only option to process the SQL-recordset field to look for the single
quote? I'm hoping that excel's object model has some way to detect the
forcing of a cells value to text.

--
Regards,
John

Gary''s Student

Detecting a single quote from a cells value
 
Sub apostest()
MsgBox (Range("A1").PrefixCharacter)
End Sub

--
Gary''s Student - gsnu200736


"John Keith" wrote:

I need to know when the input data contains the prefixed single quote to
force the data to be treated like text.

I am showing SQL table data that contains scripting commands. The presence
of a single tick indicates that this script command is a comment. I want to
process through my script commands and turn the font to green when the script
command being displayed in a cell is a comment.

How do I detect the presence of a prefixed single quote in a cell from VBA?
Left$(cell.value, 1) = "'" is never true because excel strips this
character from the value (although it is still shown in the formula bar)
Neither does the cell.formula show the prefixed single quote (this seems
like it should though)

Is my only option to process the SQL-recordset field to look for the single
quote? I'm hoping that excel's object model has some way to detect the
forcing of a cells value to text.

--
Regards,
John


John Keith[_2_]

Detecting a single quote from a cells value
 
Exactly what I needed, Gary would be proud.

Thanks!

--
Regards,
John


"Gary''s Student" wrote:

Sub apostest()
MsgBox (Range("A1").PrefixCharacter)
End Sub

--
Gary''s Student - gsnu200736


"John Keith" wrote:

I need to know when the input data contains the prefixed single quote to
force the data to be treated like text.

I am showing SQL table data that contains scripting commands. The presence
of a single tick indicates that this script command is a comment. I want to
process through my script commands and turn the font to green when the script
command being displayed in a cell is a comment.

How do I detect the presence of a prefixed single quote in a cell from VBA?
Left$(cell.value, 1) = "'" is never true because excel strips this
character from the value (although it is still shown in the formula bar)
Neither does the cell.formula show the prefixed single quote (this seems
like it should though)

Is my only option to process the SQL-recordset field to look for the single
quote? I'm hoping that excel's object model has some way to detect the
forcing of a cells value to text.

--
Regards,
John


Rick Rothstein \(MVP - VB\)

Detecting a single quote from a cells value
 
"Gary''s Student" wrote:

Sub apostest()
MsgBox (Range("A1").PrefixCharacter)
End Sub


Exactly what I needed, Gary would be proud.


Well, Gary might be proud except, perhaps, for those extraneous parentheses
around the MsgBox argument.<g

Rick



All times are GMT +1. The time now is 11:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com