Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / November 2006

Tip: Looking for answers? Try searching our database.

How to remove text strings that exceed a certain value within specified range.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
graham.mike@gmail.com - 28 Nov 2006 22:07 GMT
I've been looking for a soultion for my issue for some time now and was
very happy to find the following resolution posted a little over a year
ago.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
       Const nMAX As Long = 910
       Dim rCell As Range
       Set Target = Intersect(Target, Columns(1))
       If Not Target Is Nothing Then
           For Each rCell In Target
               With rCell
                   If Len(.Text) > nMAX Then
                       MsgBox "The text in cell " & _
                           .Address(False, False) & " is too long (" &
_
                           Len(.Text) & " characters)" & vbNewLine & _

                           "Max. Characters: " & nMAX
                   End If
               End With
           Next rCell
       End If
   End Sub

However, I'm looking for one modification to the code. I'd like to add
code that will remove text strings within Column A that contain more
than 910 characters after the user selects OK from the corresponding
MsgBox. Data/Validation will not work as I need to check for copy/paste
values as well. If this is not possible then, I'd like try to replace
the MsgBox code with code that will remove any text string in column A
that exceeds 910 characters.
Any help is much appreciated.
Thanks, Mike
Scott - 28 Nov 2006 23:41 GMT
Can you not just add the following code after the MsgBox?
 Application.EnableEvents = False
 rCell = ""
 Application.EnableEvents = True

Scott

> I've been looking for a soultion for my issue for some time now and was
> very happy to find the following resolution posted a little over a year
[quoted text clipped - 29 lines]
> Any help is much appreciated.
> Thanks, Mike
graham.mike@gmail.com - 29 Nov 2006 18:32 GMT
That seems to have done the trick. Thanks so much for your help.
- Mike

> Can you not just add the following code after the MsgBox?
>   Application.EnableEvents = False
[quoted text clipped - 36 lines]
> > Any help is much appreciated.
> > Thanks, Mike
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.