View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Phil Hageman[_4_] Phil Hageman[_4_] is offline
external usenet poster
 
Posts: 81
Default Message Box Improvements

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