macro help, copying font and color

airfrm

New Member
Joined
Apr 3, 2016
Messages
5
Hoping for some help with macros. I have 2 sheets in a workbook. the second sheet is copied from the "yesterday" with notes and some of those notes are in bold and different font colors. when I run the macro I'm wanting to keep the font from the day prior to carry over to the current day without effecting any new notes. It is copying all the info correctly except the bold or any font colors.


ElseIf Len(ActiveSheet.Cells(x, 2)) = 0 And Len(ActiveSheet.Cells(x, 3)) <> 0 Then 'Gripe row

ActiveSheet.Cells(x, lastcol).HorizontalAlignment = xlLeft 'set horiz alignment for remarks
ActiveSheet.Cells(x, 3).HorizontalAlignment = xlLeft 'nomenclature

'import yesterday's notes
vReturn = Application.Match(Range("L" & x).Value, Worksheets("Yesterday").Range("L:L"), 0)
If IsError(vReturn) Then
Range("B" & x).Value = " "
Else
ActiveSheet.Range("B" & x).Value = Application.Index(Worksheets("Yesterday").Range("B:B"), vReturn)
Worksheets("Yesterday").Range("B" & vReturn).Copy
ActiveSheet.Range("B" & x).PasteSpecial xlPasteFormats
ActiveSheet.Range("B" & x).Font.Name = "Arial"
ActiveSheet.Range("B" & x).Font.Size = 11
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Your code in VBA code brackets (please use this when posting code, click the little VBA icon above the post area):
VBA Code:
lseIf Len(ActiveSheet.Cells(x, 2)) = 0 And Len(ActiveSheet.Cells(x, 3)) <> 0 Then 'Gripe row

ActiveSheet.Cells(x, lastcol).HorizontalAlignment = xlLeft 'set horiz alignment for remarks
ActiveSheet.Cells(x, 3).HorizontalAlignment = xlLeft 'nomenclature

'import yesterday's notes
vReturn = Application.Match(Range("L" & x).Value, Worksheets("Yesterday").Range("L:L"), 0)
If IsError(vReturn) Then
    Range("B" & x).Value = " "
Else
    ActiveSheet.Range("B" & x).Value = Application.Index(Worksheets("Yesterday").Range("B:B"), vReturn)
    Worksheets("Yesterday").Range("B" & vReturn).Copy
    ActiveSheet.Range("B" & x).PasteSpecial xlPasteFormats
    ActiveSheet.Range("B" & x).Font.Name = "Arial"
    ActiveSheet.Range("B" & x).Font.Size = 11

if vReturn has the correct value for the column with the correct formatting, then the macro should copy the formats.

But have you checked to see if vReturn has the correct value?
In the VBA editor click on the grey border just to the left of the line
VBA Code:
vReturn = Application.Match(Range("L" & x).Value, Worksheets("Yesterday").Range("L:L"), 0)
The line should turn dark red, you have set a breakpoint here. When you now run the macro, the macro will stop here for you to debug.
You will see the line with the code in yellow, showing this is the next line to be executed.
press the F8 key once, this will execute the line.
now hover your mouse over vReturn. You should see the value that it now has. Is this the correct cell to take the format from?
 
Upvote 0

Forum statistics

Threads
1,215,140
Messages
6,123,266
Members
449,093
Latest member
Vincent Khandagale

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