View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Paul Mathews Paul Mathews is offline
external usenet poster
 
Posts: 84
Default Problem deleting rows by index

Chris, I noticed that you've got a single quote in front of the row delete
which makes it a comment. Could that be the issue?

"Chris" wrote:

Hello Everyone,

I'm new to excel vba programming, but have a little vb.net experience.

I'm trying to delete rows by index i.e. Rows(index).Delete, but nothing is
ever deleted. The code doesn't give me an error and comes to a quiet
completion.


Thanks in advance for any help.

Chris


I might be posting more code than necessary, but because I'm a Excel
neophyte I'm thinking there might be a better way to accomplish this task.

Here is the code in question:

Dim col As New Collection

Sub mainSub()
'parse entries in index.dat (index.dat holds IE's History)
'and copy to Excel Worksheet1
'parseIndex_dat(Computername, Username)

'Remove websites unrelated to the Internet
'and store row location in collection
FindJunk ("file://")
FindJunk ("res://")
FindJunk ("host:")
FindJunk ("outlook:")
FindJunk ("about:")

RemoveJunk 'This isn't working

FindAndHighlight "hotmail", 6
FindAndHighlight "aim", 7
FindAndHighlight "messenger", 10
FindAndHighlight "myspace", 46

End Sub

Sub FindJunk(strFind As String)
Dim c As Range
With Worksheets(1).Cells ' Whole sheet
Set c = .Find(strFind, LookIn:=xlValues, Lookat:=xlPart)
If Not c Is Nothing Then
firstAddress = c.Address
Do
col.Add (c.Row)
Set c = .FindNext(c)
Loop While c.Address < firstAddress
End If
End With
End Sub

Sub RemoveJunk()
Dim element As Variant
For Each element In col
'Worksheets("Sheet1").Cells.Rows(element).Delete
'Rows(element).Delete
Worksheets("Sheet1").Cells(element).EntireRow.Dele te

'How do I delete the rows? All of the above three
'don't give me a compile error

Next
End Sub

Sub FindAndHighlight(strFind As String, color As Integer)
Dim c As Range
With Worksheets(1).Cells
Set c = .Find(strFind, LookIn:=xlValues, Lookat:=xlPart)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Interior.ColorIndex = color
Set c = .FindNext(c)
Loop While c.Address < firstAddress
End If
End With
End Sub