Message Box Improvements

G

Guest

This code counts the characters and spaces in a cell. Could the message box
be modified to also show the sum of characters and spaces, as well as a text
statement “Characters > 255 will not paste�

Sub CountCharacters()
Dim StringLength As Integer
Dim EmptySpaces As Integer
Dim I As Integer
Dim CellRef As Variant
CellRef = Trim(ActiveCell.Value)
StringLength = Len(ActiveCell.Value)
For I = 1 To Len(ActiveCell.Value)
If Mid(CellRef, I, 1) = " " Then EmptySpaces = EmptySpaces + 1
Next
MsgBox "Characters: " & StringLength & Chr(10) & "Empty Spaces: " &
EmptySpaces
End Sub
 
B

Bob Phillips

Do you mean

MsgBox "Characters: " & StringLength & Chr(10) & _
"Empty Spaces: " & EmptySpaces & Chr(10) & _
"CharCharacters > 255 will not paste"
 
G

Guest

Hi Bob,

Getting closer. Need somehting like:

Characters 215
Spaces 22
Total 237

Text message is good.

Phil
 
B

Bob Phillips

MsgBox "Characters: " & StringLength & vbnewline & _
"Spaces: " & EmptySpaces & vbNewLine & _
"Total " & StringLength + EmptySpaces
 

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

Similar Threads


Top