copyorigin, but only from Left or right column, and not above or below.

freddie mitchell

New Member
Joined
Apr 14, 2011
Messages
43
Hello everyone and happy new year,

Quick question on VBA formatting.

I've got a code, pasted below, with an insert row function. The code works well, but one small issue is that the copyorigin section copies the format of cells above and below the inserted row. The cells above and below are, however, typically hyperlinked, meaning that the newly inserted row appears with a hyperlink. Is there a way to either set the format to a default setting? Or to copy the formatting of a specific cell that is formatted correctly?

VBA Code:
.Rows(r).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrBelow

Thank you for all your help,

You're all great! :)
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
You would need to make any 'corrections' to the formatting after the row is inserted, something like
VBA Code:
.Rows(r).Hyperlinks.Delete
if additional formatting changes are needed then either you can either apply them directly from your code or use pastespecial - formats.
If using pastespecial, try to limit it to the used columns only in order to reduce risk of potential file bloat.
 
Upvote 0
Hi Jason,

thank you for this. To double check, does the
VBA Code:
.Rows(r).Hyperlinks.Delete
need to have its own separate sub? I tried adding it to the insert row sub but it didn't work, probably because I put it in the wrong place!

Thank you for your help,
 
Upvote 0
I would add it to the same sub as the next line after the row is inserted.

It might cause an error if there are no hyperlinks, if that is the case then try
VBA Code:
    .Rows(r).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrBelow
On Error Resume Next
    .Rows(r).Hyperlinks.Delete
On Error Goto 0
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

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