Remove hyperlinks while retaining formatting

scottcolbury

New Member
Joined
Dec 6, 2005
Messages
45
Hi,
I have some legacy workbooks with embedded hyperlinks that I need to get rid of.
I know how to remove the links, but when doing so Excel resets the number formatting to general, removes colors, bold, italics, etc, etc. I need to retain this formatting.

I tried copying the cell to then use paste special:formatting, but that does not work.
Here is version of my code.

Code:
        With ActiveSheet
            LastRow = .Cells(65536, 2).End(xlUp).Row
            'test all cells with visible data
            For x = 1 To LastRow
                For y = 1 To 256
                    Application.StatusBar = "x = " & x & " of " & LastRow & " : y = " & y
                    If .Cells(x, y).Hyperlinks.Count > 0 Then
                        .Cells(x, y).Hyperlinks(1).Delete
                    End If
                Next y
            Next x
        End With

thanks
s_c
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Yes, I know the shorter code will work... but that still doesn't help me with my problem of retaining the formatting.
s_c
 
Upvote 0
Try (on a copy of your sheet)

Code:
Sub test()
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = ActiveSheet
ActiveSheet.Copy after:=ActiveSheet
Set ws2 = ActiveSheet
ws1.Hyperlinks.Delete
ws2.UsedRange.Copy
ws1.Range("A1").PasteSpecial Paste:=xlPasteFormats
ws1.Select
Application.DisplayAlerts = False
ws2.Delete
Application.DisplayAlerts = True
End Sub
 
Upvote 0
Thanks Andrews, but that wasn't the kind of formatting I was referring to.
I'm talking about the formatting I do regardless if the hyperlink has been clicked.
s_c
 
Upvote 0
Thanks VoG,
This code works for the most part, but XLS won't paste formats over array formulas at this line:

Code:
ws1.Range("A1").PasteSpecial Paste:=xlPasteFormats

... and the code breaks.
Any ideas?

s_c
 
Upvote 0
This may take a while to run with a large sheet but will skip cells that cause errors:

Code:
Sub test()
Dim ws1 As Worksheet, ws2 As Worksheet, c As Range
Application.ScreenUpdating = False
Set ws1 = ActiveSheet
ActiveSheet.Copy after:=ActiveSheet
Set ws2 = ActiveSheet
ws1.Hyperlinks.Delete
On Error Resume Next
For Each c In ws2.UsedRange
    c.Copy
    ws1.Range(c.Address).PasteSpecial Paste:=xlPasteFormats
Next c
On Error GoTo 0
ws1.Select
Application.DisplayAlerts = False
ws2.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

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