Character count of a Cell in a Table

  • Thread starter Thread starter Bhimsen
  • Start date Start date
B

Bhimsen

Can we find the number of characters a cell may contain in a table by writing
a new macros ? If yes, how?
 
You may use the following as a starting point (I don't know how you want to
use the count).

The following line of code will show the number of characters in the first
cell in the selection, incl. the end of cell marker (which counts 2) – in
case of a single cell, you do not need to select the text first. It is
sufficient that the insertion point be in the cell:

MsgBox Len(Selection.Cells(1).Range)


If you want to exclude the end of cell marker, subtract 2 from the count:

MsgBox Len(Selection.Cells(1).Range) - 2

For example, if the cell contains the text "This is my text" (a total of 15
characters), the first code line will 17 and the second will return 15.

Please post back if you need help with the entire macro. In that case, you
need to explain how you want to use the macro.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
I want to find out how many characters can a blank cell contain.(the cell
doesn't contain any text).
Once the marker is placed in the cell and the macros is run, is it possible
to find the number of characters the cell can contain maximum.(The Row height
is fixed and wrap text and fit text options have been disabled.)
 
Is the table part of a protected form that is going to be filled in?
I am not sure you can find a good method. Maybe others will come up with a
solution you like. Unless you are using a monospaced font, characters have
different widths (i and m). Also, the user could hit Return. In case of a
text form field, you could set a maximum length of the text via Text Form
Field Options.

Even if the user enters text that breaks into more lines so that part of the
text is not visible, you can still access all the text via VBA.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top