macro - delete row if cell contains string

  • Thread starter Thread starter alex.kemsley
  • Start date Start date
A

alex.kemsley

Hi all,

Can some one help me please!
Here is a slightly more complex macro that I really need. I have a list
of domain names in excel for example:

1 www.throneofnails.com
2 www.throneofnails.com/info/index.html
3 www.fairkess.com/en/business/industrie.html
4 www.endlessdecor.com/Links.html
5 www.retractableawnings.com/resources.htm
6 www.ffbd-tm.com
7 www.ffbd-tm.com/test

I need a macro that will delete all the top level domain names eg
www.throneofnails.com and delete all files in that domain eg
www.throneofnails.com/info/index.html.

I need to be left with a list of only domain names like domain name 3,4
and 5.

I think it will probably have something to do with finding the cells
that dont contain a "/" then loading them into an array then deleting
all cells that contain the contents of that array.

Unfortunately I dont have the programing language to do this.

Your help would be much appreciated.

Many thanks

Alex Kemsley
 
You could use a helper column with formulas like:

=isnumber(search("/",a2))

Then drag it down the column.

Then apply data|filter|autofilter to that column.
Show the Trues and delete those visible rows.
 
Sub hij()
Dim i As Long, j As Long, s As String
i = 1
Do While Not IsEmpty(Cells(i, 1))
If InStr(1, Cells(i, 1), "/", vbTextCompare) = 0 Then
s = Cells(i, 1)
j = i + 1
Do While InStr(1, Cells(j, 1), s, vbTextCompare) <> 0
j = j + 1
Loop
Range(Cells(i, 1), Cells(j - 1, 1)).EntireRow.Delete
Else
i = i + 1
End If
Loop
End Sub

worked for me with your data.
 
You can try something similar to this:
Dim rng As Range
Columns("A:A").Select
For Each rng In Selection
rng.Activate
If ActiveCell.Value <> "" And InStr(1, ActiveCell.Value, "/") = 0 Then
ActiveCell.Delete (xlShiftUp)
ActiveCell.Offset(1, 0).Activate
End If
Next
 
Thanks dave,
It works great for the top level domains,
But I need to be able to delete the files of the domains it deletes
too.
Any Idea how i can do that too?
Alex
 
Sub hij()
Dim i As Long, j As Long, s As String
i = 1
Do While Not IsEmpty(Cells(i, 1))
If InStr(1, Cells(i, 1), "/", vbTextCompare) = 0 Then
s = Cells(i, 1)
j = i + 1
Do While InStr(1, Cells(j, 1), s, vbTextCompare) <> 0
j = j + 1
Loop
Range(Cells(i, 1), Cells(j - 1, 1)).EntireRow.Delete
Else
i = i + 1
End If
Loop
End Sub

worked for me with your data.
 
sorry jim,
I dont seem to be able to get that to work, it deleted about 10 of them
but left the rest, i cant seem to work out why.
alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top