Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default deleting a cell based on character length?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default deleting a cell based on character length?

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default deleting a cell based on character length?

On Aug 7, 12:30 pm, Vergel Adriano
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Indent based on character length Scott Excel Discussion (Misc queries) 4 July 20th 09 04:36 AM
Predefined Cell Character Length Matt Excel Worksheet Functions 4 March 5th 09 10:21 PM
assigning character length in a cell Audrey Excel Discussion (Misc queries) 4 July 30th 06 04:40 PM
Deleting the same character automatically in each cell fuzzyjon Excel Worksheet Functions 3 May 15th 06 02:45 PM
How do I limit the character length of a cell when typing Andy Excel Programming 1 July 27th 05 03:54 PM


All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"