Thread Closed 
Thread Rating:
  • 28 Vote(s) - 3.18 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete rows in spreadsheet that are not needed
Author Message
dwinn86 Offline
Junior Member

Posts: 1
Joined: Oct 2011
Reputation: 0
Post: #1
Delete rows in spreadsheet that are not needed

Hi everyone,

I am not sure if I am in the correct forum so here goes.

I am trying to write a program in VBA that grabs a spreadsheet from my computers desktop, opens the spreadsheet, looks at a particular column and loops through the spreadsheet (just looking at this one column throughout the spreadsheet) looking for the following words ('Data Due', 'Files Due', Indent Due', 'Quantities Due').

The program loops through the spreadsheet looking at this one column and if the cell doesnt contain any of these words, the entire row gets deleted.

It then loops through this column until the end of the file is reached.

I have produced a bit of code, but have hit the point where I am getting stumped for what to do next.

The code is as follows:

Option Compare Database

Sub ExamsListFormat()
Dim LineData As String
Dim dansArray As Variant
Dim dansRange As Range
Dim I As Long

' Open the spreadsheet
Open "C:\Test\testdoc.xls" For Input As #1

dansArray = Array("Indent", "Files Due", "Quantities Due")

Do While Not EOF(1)

' Read a line of data.
Line Input #1, LineData

For I = LBound(dansArray) To UBound(dansArray)

'Sheet with the data
With ActiveSheet

'Firstly, remove the AutoFilter
.AutoFilterMode = False

'Apply the filter
.Range("O2:O" & .Rows.Count).AutoFilter Field:=1, Criteria1:=dansArray(I)

Set dansRange = Nothing
With .AutoFilter.Range
On Error Resume Next
Set dansRange = .Offset(1, 0).Resize(.Rows.Count - 1, 1) .SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then dansRange.EntireRow.Delete
End With

'Remove the AutoFilter
.AutoFilterMode = False
End With

Next I

With Application
.ScreenUpdating = True
.Calculation = calcmode
End With

' Close the data file.
Close #1

MsgBox "Document Scanned Successfully..."
End Sub

All advice will be much appreciated.

Many Thanks,

10-04-2011 01:28 AM
Find all posts by this user
Squall Leonhart Offline
The Admin with the Gunblade

Posts: 1,506
Joined: Mar 2008
Reputation: 17
Post: #2
RE: Delete rows in spreadsheet that are not needed


This thread will remain as a testament to the many fools who simply fail at reading.

(This post was last modified: 10-05-2011 02:53 AM by Squall Leonhart.)
10-05-2011 02:52 AM
Visit this user's website Find all posts by this user
Thread Closed 

Forum Jump:

User(s) browsing this thread: 1 Guest(s)

 Quick Theme: