Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Auto delete contents

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Auto delete contents

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

" 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Auto delete contents

On Oct 9, 8:14 pm, OssieMac
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



" 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Auto delete contents

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Auto delete contents

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
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
Auto fit contents Una Pregunta Excel Discussion (Misc queries) 1 January 27th 10 05:47 PM
delete contents of cell RDC Excel Discussion (Misc queries) 1 January 21st 09 04:13 PM
Delete cell contents Rob[_4_] Excel Discussion (Misc queries) 7 April 10th 07 12:34 PM
Delete Cell Contents IF joecrabtree Excel Programming 3 December 18th 06 02:21 PM
How to Delete Contents of D2 if B2 = "SD" StarBoy2000 New Users to Excel 5 July 21st 05 06:46 PM


All times are GMT +1. The time now is 02:31 PM.

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

About Us

"It's about Microsoft Excel"