Keep source formatting in vba

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
365
Hi, in the below code if possible I would kike to have the source font color / style, such as red or bold" remain when being copied from sheet "master" to sheet "new invent". Thanks for the help.

VBA Code:
Worksheets("MASTER").Activate

Range("A1:H1000").Copy Destination:=Sheets("NEW INVENT").Range("A1")
Range("A1:H1000").Copy
Sheets("NEW INVENT").Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
 
Last edited by a moderator:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Why are doing the copy twice? The first copy should paste everything including source formats.
 
Upvote 0
Try it with just this code and let us know what it does.

VBA Code:
Worksheets("MASTER").Activate

Range("A1:H1000").Copy Destination:=Sheets("NEW INVENT").Range("A1")
 
Upvote 0
Your code does copy the formatting, but I have other macros following it and my font color goes from red back to black. I think it's happening in the code below which runs next, but I don't know why.

VBA Code:
Sub Text_To_Col()

    Worksheets("NEW INVENT").Activate
    Range("A5:A1000").Select
  
    Selection.TextToColumns Destination:=Range("C5"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :="-", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _
        1), Array(6, 2)), TrailingMinusNumbers:=True
        
        Columns("A:B").Delete
        Range("E:E").NumberFormat = "0"
        
        Range("A:C").HorizontalAlignment = xlCenter
        Range("D:D").HorizontalAlignment = xlLeft
        Range("E:F").HorizontalAlignment = xlCenter
               
End Sub
 
Upvote 0
Formatting is not carried over when you do Text To Columns. Maybe do this after the text to columns. I have not tested this yet.

VBA Code:
Range("A1:H1000").Copy
Sheets("NEW INVENT").Range("C1:F1").PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
 
Upvote 0
I assumed the result of your text to columns would be in C:F
 
Upvote 0
Because the second time you are just copying and pasting the formats only, to the new columns created by TTC.

Rich (BB code):
Sheets("NEW INVENT").Range("C1:F1").PasteSpecial Paste:=xlPasteFormats
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
Members
448,973
Latest member
ChristineC

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