A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Basic Row Delete Marco



 
 
Thread Tools Display Modes
  #1  
Old July 10th 12, 11:45 AM
SalientAnimal SalientAnimal is offline
Junior Member
 
First recorded activity by ExcelBanter: Dec 2010
Posts: 15
Exclamation Basic Row Delete Marco

Hi Guys/Gals,

I'm looking for a very basic marco that will delete an entire row if the cell in column U contains any text/value.

Thanks
Ads
  #2  
Old July 10th 12, 12:46 PM
SalientAnimal SalientAnimal is offline
Junior Member
 
First recorded activity by ExcelBanter: Dec 2010
Posts: 15
Default

Quote:
Originally Posted by SalientAnimal View Post
Hi Guys/Gals,

I'm looking for a very basic marco that will delete an entire row if the cell in column U contains any text/value.

Thanks
Found a solution:

Sub DelRows()
Application.ScreenUpdating = False
With ActiveSheet.UsedRange
.AutoFilter Field:=7, Criteria1:=">=a"
.Offset(1).EntireRow.Delete
.AutoFilter
End With
Application.ScreenUpdating = True
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft
End Sub

Where .AutoFilter Field:=7, the 7 indicates the column number.
  #3  
Old July 10th 12, 04:21 PM posted to microsoft.public.excel.programming
joeu2004[_2_]
external usenet poster
 
Posts: 637
Default Basic Row Delete Marco

"SalientAnimal" > wrote:
> I'm looking for a very basic marco that will delete an
> entire row if the cell in column U contains any text/value.


Not sure what you mean by "any text/value". Do you really mean "a specific
value"? Or do you mean "not a formula and not empty"? Do you mean simply
"not empty"?

I assume you mean "a specific value".

The following will delete rows conditionally over a selected region.


Sub doit()
Const mycol = "U"
const myval = 4 ' your "specific value" (my assumption)
Dim nr As Long, i As Long
Dim rng As Range, r as Range
Application.ScreenUpdating = False
rng = Selection ' your own range
nr = rng.Rows.Count
' important: process rows in reverse when deleting
For i = nr To 1 Step -1
Set r = rng.Cells(i, 1).EntireRow
If r.Cells(1, mycol) = myval Then r.Delete
Next
Application.ScreenUpdating = True
End Sub

  #4  
Old July 10th 12, 11:49 PM posted to microsoft.public.excel.programming
Don Guillett[_2_]
external usenet poster
 
Posts: 1,506
Default Basic Row Delete Marco

On Tuesday, July 10, 2012 5:45:23 AM UTC-5, SalientAnimal wrote:
> Hi Guys/Gals,
>
> I'm looking for a very basic marco that will delete an entire row if the
> cell in column U contains any text/value.
>
> Thanks
>
>
>
>
> --
> SalientAnimal


filtering faster than loop
Sub DeleteNonBlanksinColumnSAS()
'column U is colummn 21
'Assumes columns a:u have date on header row
Application.ScreenUpdating = False
With ActiveSheet.UsedRange ' or Range("a2:u20000")
.AutoFilter Field:=21, Criteria1:="<>"
.Offset(1).EntireRow.Delete
.AutoFilter
End With
Application.ScreenUpdating = True
End Sub
  #5  
Old July 10th 12, 11:50 PM posted to microsoft.public.excel.programming
Don Guillett[_2_]
external usenet poster
 
Posts: 1,506
Default Basic Row Delete Marco

On Tuesday, July 10, 2012 5:45:23 AM UTC-5, SalientAnimal wrote:
> Hi Guys/Gals,
>
> I'm looking for a very basic marco that will delete an entire row if the
> cell in column U contains any text/value.
>
> Thanks
>
>
>
>
> --
> SalientAnimal


dSub DeleteNonBlanksinColumnSAS()
'column U is colummn 21
'Assumes columns a:u have date on header row
Application.ScreenUpdating = False
With ActiveSheet.UsedRange 'Range("F2:J200")
.AutoFilter Field:=21, Criteria1:="<>"
.Offset(1).EntireRow.Delete
.AutoFilter
End With
Application.ScreenUpdating = True
End Sub
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can delete file by Marco Hello Excel Programming 13 February 13th 11 01:20 AM
Marco to Delete Worksheets CM4@FL Excel Discussion (Misc queries) 2 February 27th 09 07:26 PM
marco to delete rows Johnfli Excel Discussion (Misc queries) 2 January 11th 07 04:50 PM
A Marco Delete Question [email protected] Excel Programming 1 July 16th 04 08:59 PM
Visual Basic Marco Andrew[_37_] Excel Programming 4 June 29th 04 04:42 AM


All times are GMT +1. The time now is 07:44 AM.


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