PC Review


Reply
Thread Tools Rate Thread

Auto delete contents

 
 
allaboutthenationals@gmail.com
Guest
Posts: n/a
 
      10th Oct 2007
Ok, I have a sheet which has a ton of data. I want to delete data only
from 2002-2006, the whole row to be deleted if column F says anything
other than IND
Thanks

 
Reply With Quote
 
 
 
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      10th Oct 2007
Hi,

Sub Delete_Rows()

Dim rngF As Range
Dim c As Range
Dim i As Long

Set rngF = ActiveSheet.Range(Cells(1, "F"), _
Cells(Rows.Count, "F").End(xlUp))

'Work backwards from bottom to top when deleting rows
With rngF
For i = .Rows.Count To 1 Step -1
If .Cells(i) <> "IND" Then
.Cells(i).EntireRow.Delete
End If
Next i
End With
End Sub


Regards,

OssieMac

"(E-Mail Removed)" wrote:

> Ok, I have a sheet which has a ton of data. I want to delete data only
> from 2002-2006, the whole row to be deleted if column F says anything
> other than IND
> Thanks
>
>

 
Reply With Quote
 
allaboutthenationals@gmail.com
Guest
Posts: n/a
 
      10th Oct 2007
On Oct 9, 8:14 pm, OssieMac <Ossie...@discussions.microsoft.com>
wrote:
> Hi,
>
> Sub Delete_Rows()
>
> Dim rngF As Range
> Dim c As Range
> Dim i As Long
>
> Set rngF = ActiveSheet.Range(Cells(1, "F"), _
> Cells(Rows.Count, "F").End(xlUp))
>
> 'Work backwards from bottom to top when deleting rows
> With rngF
> For i = .Rows.Count To 1 Step -1
> If .Cells(i) <> "IND" Then
> .Cells(i).EntireRow.Delete
> End If
> Next i
> End With
> End Sub
>
> Regards,
>
> OssieMac
>
>
>
> "allaboutthenation...@gmail.com" wrote:
> > Ok, I have a sheet which has a ton of data. I want to delete data only
> > from 2002-2006, the whole row to be deleted if column F says anything
> > other than IND
> > Thanks- Hide quoted text -

>
> - Show quoted text -


I'm sorry but that deleted the entire sheet

 
Reply With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      11th Oct 2007
It works under test with me so I must assume that the cells in column F which
are not to be deleted do not have IND in them. Perhaps they have some other
characters before or after the IND. (These could be spaces or some other
undisplayed characters).

I hope that you didn't save the workbook and that you did not loose your data.

The following searches for the string IND in the cell so will not matter if
there are other characters also.

Sub Delete_Rows()

Dim rngF As Range
Dim c As Range
Dim i As Long

Set rngF = ActiveSheet.Range(Cells(1, "F"), _
Cells(Rows.Count, "F").End(xlUp))

'Work from bottom when deleting rows
With rngF
For i = .Rows.Count To 1 Step -1
If InStr(1, .Cells(i), "IND") = 0 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With
End Sub


Regards,

OssieMac


 
Reply With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      11th Oct 2007
My comment "I hope that you didn't save the workbook and that you did not
loose your data" should have said:-
I hope that you didn't save the workbook (after running the macro) and that
you did not loose your data and were able to recover it.

Regards,

OssieMac


"OssieMac" wrote:

> It works under test with me so I must assume that the cells in column F which
> are not to be deleted do not have IND in them. Perhaps they have some other
> characters before or after the IND. (These could be spaces or some other
> undisplayed characters).
>
> I hope that you didn't save the workbook and that you did not loose your data.
>
> The following searches for the string IND in the cell so will not matter if
> there are other characters also.
>
> Sub Delete_Rows()
>
> Dim rngF As Range
> Dim c As Range
> Dim i As Long
>
> Set rngF = ActiveSheet.Range(Cells(1, "F"), _
> Cells(Rows.Count, "F").End(xlUp))
>
> 'Work from bottom when deleting rows
> With rngF
> For i = .Rows.Count To 1 Step -1
> If InStr(1, .Cells(i), "IND") = 0 Then
> .Cells(i).EntireRow.Delete
> End If
> Next i
> End With
> End Sub
>
>
> Regards,
>
> OssieMac
>
>

 
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
Auto fit contents Una Pregunta Microsoft Excel Misc 1 27th Jan 2010 05:47 PM
auto table of contents possible ? Paul Microsoft Word Document Management 7 25th Jan 2009 03:41 AM
auto delete Junk E-Mail folder contents on exiting Outlook =?Utf-8?B?ZG1laWdlbA==?= Microsoft Outlook Discussion 1 3rd May 2006 01:11 PM
contents delete when i delete a table =?Utf-8?B?ZGI=?= Microsoft Word Document Management 1 26th Jan 2005 11:29 AM
File Properties->Contents (tab)->Document Contents->fonts used (delete a font) Marina Microsoft Powerpoint 1 22nd Oct 2003 05:56 AM


Features
 

Advertising
 

Newsgroups
 


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