PC Review


Reply
Thread Tools Rate Thread

deleting a cell based on character length?

 
 
Marcusdmc
Guest
Posts: n/a
 
      7th Aug 2007
if I wanted to delete a cell in my selected row that was shorter than
say 16 characters, how would I create a macro to do that?

I would be checking for LEN(A:A) < 16 then delete?

Thanks for any help!

-Marcus

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      7th Aug 2007
To clear the cell contents of anything with <16 characters in Column A, try
something like this:

Sub test()
Dim c As Range
For Each c In Application.Intersect(ActiveSheet.UsedRange,
ActiveSheet.Range("A:A"))
If Len(c.Value) < 16 Then
c.Clear
End If
Next c
End Sub

If you want to delete the entire row instead of just clearing the cell, then
something like this:

Sub test2()
Dim c As Range
Dim rngDelete As Range
For Each c In Application.Intersect(ActiveSheet.UsedRange,
ActiveSheet.Range("A:A"))
If Len(c.Value) < 16 Then
If rngDelete Is Nothing Then
Set rngDelete = c
Else
Set rngDelete = Application.Union(c, rngDelete)
End If
End If
Next c
If Not rngDelete Is Nothing Then rngDelete.EntireRow.Delete

End Sub


--
Hope that helps.

Vergel Adriano


"Marcusdmc" wrote:

> if I wanted to delete a cell in my selected row that was shorter than
> say 16 characters, how would I create a macro to do that?
>
> I would be checking for LEN(A:A) < 16 then delete?
>
> Thanks for any help!
>
> -Marcus
>
>

 
Reply With Quote
 
Marcusdmc
Guest
Posts: n/a
 
      7th Aug 2007
On Aug 7, 12:30 pm, Vergel Adriano
<VergelAdri...@discussions.microsoft.com> wrote:
> To clear the cell contents of anything with <16 characters in Column A, try
> something like this:
>
> Sub test()
> Dim c As Range
> For Each c In Application.Intersect(ActiveSheet.UsedRange,
> ActiveSheet.Range("A:A"))
> If Len(c.Value) < 16 Then
> c.Clear
> End If
> Next c
> End Sub
>
> If you want to delete the entire row instead of just clearing the cell, then
> something like this:
>
> Sub test2()
> Dim c As Range
> Dim rngDelete As Range
> For Each c In Application.Intersect(ActiveSheet.UsedRange,
> ActiveSheet.Range("A:A"))
> If Len(c.Value) < 16 Then
> If rngDelete Is Nothing Then
> Set rngDelete = c
> Else
> Set rngDelete = Application.Union(c, rngDelete)
> End If
> End If
> Next c
> If Not rngDelete Is Nothing Then rngDelete.EntireRow.Delete
>
> End Sub
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
>
> "Marcusdmc" wrote:
> > if I wanted to delete a cell in my selected row that was shorter than
> > say 16 characters, how would I create a macro to do that?

>
> > I would be checking for LEN(A:A) < 16 then delete?

>
> > Thanks for any help!

>
> > -Marcus- Hide quoted text -

>
> - Show quoted text -


Thanks for the direction! Turned off screen updating to make it go
faster!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Indent based on character length Scott Microsoft Excel Misc 4 20th Jul 2009 04:36 AM
Indent based on character length Scott Microsoft Access 2 16th Jul 2009 09:32 PM
Validate Cell Character Length with VBA Ron Microsoft Excel Programming 4 13th Apr 2009 05:13 AM
Predefined Cell Character Length Matt Microsoft Excel Worksheet Functions 4 5th Mar 2009 10:21 PM
assigning character length in a cell =?Utf-8?B?YXVkcmV5?= Microsoft Excel Misc 6 31st Oct 2006 11:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:59 PM.