Using Wildcards and Deleting Rows

mobiius

New Member
Joined
Mar 30, 2011
Messages
37
Oh man...
Ok, I'm trying to write some VBA that will scan through approximately 16,000 lines of code in a .csv sheet and delete any row where the value in column C does not contain .htm

Here's a sample of the text in the .csv sheet:

The IP Address (actual values changed for security reasons) is in column A.
example: 1.1.11.111

The time and date is in column B.
example: [18/Apr/2011:05:56:17 -0400]

The rest is in column C.
GET /...path.../whskin_tbars.htm HTTP/1.1
GET /...path.../whproxy.js HTTP/1.1

...and so on.

I am using the following code. It scans the file, but then it ends up deleting every row...

Code:
Do Until ActiveCell.Value = ""
    Workbooks.Open Filename:=ActiveCell.Value
    Range("C1").Select
    Do Until ActiveCell.Value = ""
        If ActiveCell.Value = "*htm HTTP/1.1" Then
            ActiveCell.Offset(1, 0).Activate
        Else
            ActiveCell.EntireRow.Delete
        End If
    Loop
    Windows("KR Page Access Report Generator.xls").Activate
    ActiveCell.Offset(1, 0).Activate
Loop

Any thoughts on how to fix this?
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this

Code:
Sub test()
Dim lr As Long, i As Long, x As Long
lr = Cells(Rows.Count, "C").End(xlUp).Row
For i = lr To 1 Step -1
    x = InStr(1, Cells(i, "C").Value, ".htm")
    If x = 0 Then Rows(i).EntireRow.Delete
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,763
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top