VBA Code not keeping hyperlinks when pasting

Lrees

New Member
Joined
Feb 7, 2018
Messages
12
Hi all,
Have some VBA code that copies data from 1 list and then pastes any entries that don't already exist.
The issue that I have is that in column A the cells also has a hyperlink and some formatting.

Code is below if anyone is steer my in the right direction.

Cheers

Code:
Sub CopyUnique()Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range
Set sh1 = Sheet2
Set sh2 = Sheet1
lr = sh1.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh1.Range("A1:A" & lr)
For Each c In rng
If WorksheetFunction.CountIf(sh2.Range("A:A"), c.Value) = 0 Then
sh2.Range("A" & sh2.Cells(Rows.Count, 1).End(xlUp).Row)(2).Resize(1, 4) = c.Resize(1, 4).Value
End If
Next
End Su
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I always like it when users ask questions if they were to just say in words what their trying do instead of showing us their code which is not doing what they want to achieve

And especially when you say:

Set sh1 = Sheet2
Set sh2 = Sheet1

Sort of like why might you say Jane=Bill and Sally= David

But that's just me my Brain has a hard time with this.
 
Upvote 0
Hi My Answer Is This,
Apologies for not explaining, the VBA was note created by myself.

Overlooked the Sh1 / Sh2 part, I had amended that to suit which sheets my tables sit on.

I'll try and explain best I can...

I have 2x lists on separate worksheets. I wanted to copy all new/unique entries from the one list and add to the bottom of the "master list" that sits on the separate worksheet. The above VBA works perfectly for that.
The issue I have is that is is pasting the values only and not carrying the formatting and hyperlinks across.
 
Upvote 0
Managed to get a working solution. Code below for anyone experiencing similar.

Code:
Sub CopyUnique()Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range
Set sh1 = Sheet1 'Master list'
Set sh2 = Sheet2 'Back list that I wanted to copy the date from'
lr = sh2.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh2.Range("A1:A" & lr)
For Each c In rng
If WorksheetFunction.CountIf(sh1.Range("A:A"), c.Value) = 0 Then
c.Resize(1, 4).Copy
sh1.Range("A" & sh1.Cells(Rows.Count, 1).End(xlUp).Row)(2).Resize(1, 4).PasteSpecial


End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,304
Members
448,564
Latest member
ED38

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