ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro syntax to check string length in a cell (https://www.excelbanter.com/excel-discussion-misc-queries/117076-macro-syntax-check-string-length-cell.html)

El Bee

Macro syntax to check string length in a cell
 
I'm trying to find the VB syntax for checking the length of a string in a
cell.
Any takers? I'm stuck.

Gord Dibben

Macro syntax to check string length in a cell
 
mystring = ActiveCell.Value
mylen = Len(mystring)
MsgBox mylen


Gord Dibben MS Excel MVP

On Wed, 1 Nov 2006 12:16:02 -0800, El Bee
wrote:

I'm trying to find the VB syntax for checking the length of a string in a
cell.
Any takers? I'm stuck.



Gary''s Student

Macro syntax to check string length in a cell
 
Sub lcheck()
MsgBox (Len(Selection.Value))
End Sub

Select a cell adn run the macro.
--
Gary's Student


"El Bee" wrote:

I'm trying to find the VB syntax for checking the length of a string in a
cell.
Any takers? I'm stuck.


Dave Peterson

Macro syntax to check string length in a cell
 
if len(worksheets("sheet1").range("a1").value) 3 then
or
if len(worksheets("sheet1").range("a1").text) 3 then

..text is what you see in the cell. .value is what the cell actually contains.

===
If you put 3 in a cell, the .value is 3.

But if you format it to show $3.00, then .text is $3.00



El Bee wrote:

I'm trying to find the VB syntax for checking the length of a string in a
cell.
Any takers? I'm stuck.


--

Dave Peterson


All times are GMT +1. The time now is 02:19 AM.

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