Macro to remove web addresses

griffinwebnet

New Member
Joined
Aug 4, 2011
Messages
4
I have written a macro to extract the addresses from hyperlinks, and paste them in the cell to the right, it them removes the 'mailto:' if its an email address, and its supposed to delete the contents of the cell if it starts with 'http:' because were not interested in web sites. however it extracts and removes mailto: but in the last step it removes random email addresses from the list as well. addresses that dont have http: and it sometimes fails to remove actual web addresses.

Here is my code:

Code:
Sub ExtractHL()
'Extracts the destination of all hyperlinks
Dim HL As Hyperlink
    For Each HL In ActiveSheet.Hyperlinks
        HL.Range.Offset(0, 1).Value = HL.Address
    Next
'Removes Mailto from the destination addresses if an email
   Cells.Replace What:="mailto:", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
'Deletes all non email addresses
Dim cell As Range
    For Each cell In ActiveSheet.UsedRange
    If cell.Text >= "http:" Then cell.ClearContents
Next
'Removes All HyperLinks
Cells.Hyperlinks.Delete
End Sub

-JL
 

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 replacing
Code:
If cell.Text >= "http:" Then cell.ClearContents
with
Code:
If cell.Text >= "http:*" Then cell.ClearContents
 
Upvote 0
Try replacing
Code:
If cell.Text >= "http:*" Then cell.ClearContents

that didnt work. :( It is still deleting data that it shouldnt.

HJere is a sample book. since i cant post attachments, ill have tou host it on my server. http://webnetforum.com/projektor/proj/Excel/Sample_book.xlsm

When you save it it will want to save as a .zip for some reason. It's not a '.zip'. just change to all file types and add '.xlsm' to the end.

first run HLExtractor, then run httpremover and you'll see what i am talking about.

-JL
 
Upvote 0
I've had a look and can't make any sense of what is happening. I've tried several different methods to obtain the desired result without success.
Maybe someone else can have a look for you.
 
Upvote 0
What happens if you change this line...

Code:
If cell.Text >= "http:" Then cell.ClearContents
to this...

Code:
If cell.Text Like "http:*" Then cell.ClearContents
 
Upvote 0
Okay, think this may do what you want (really, I do ;)). Change your "'Deletes all non email addresses" section to this...

Code:
'Deletes all non email addresses
   Cells.Replace What:="http:*", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 
Upvote 0
Okay, think this may do what you want (really, I do ;)). Change your "'Deletes all non email addresses" section to this...

Code:
'Deletes all non email addresses
   Cells.Replace What:="http:*", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False


Thank You Thank you! That worked beautifully. i cant believe that i didnt think of it since i use the same function to remove 'mailto:'. Brilliant!

Lol. Thank You All For your help!

-JL Griffin
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,293
Members
452,902
Latest member
Knuddeluff

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