VBA Copy Cell Style Across Row

vahnx

Board Regular
Joined
Apr 10, 2011
Messages
188
I'm looking for a method of copying the exact style of each row across. Here's my example:

89166813.png


background color and border style needs to be copied across to this part:

92648947.png



Now I wrote this code here:

Code:
Sub SetRowUnifiedStyle()
  
    Dim row As Integer
    row = 1563

    For i = 2 To 15571
    
        If Range("AN" & CStr(i)) <> 0 Then

            Range("AN" & CStr(i) & ":CA" & CStr(i)).Interior.Color = Range("B" & CStr(i)).Interior.Color
            'Range("AN" & CStr(i) & ":CA" & CStr(i)).Borders.LineStyle = Range("B" & CStr(i)).Borders.LineStyle
            Range("AN" & CStr(i) & ":CA" & CStr(i)).Cells.Borders.LineStyle = Range("B" & CStr(i)).Cells.Borders.LineStyle

        End If
    
    Next i
    

End Sub

but when I run it, my result looks like this:

62726810.png


As you can see, it just carries across the dotted lines but the top, and bottom borders are also dotted. How do I copy the exact same theme across?
I tried changing from LineStyle to Weight but it just boldens them.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Edit: Updated code but the right hand side isn't copying, everything else is:

' by
'
' copy bg color/style from Sample # (B) column, apply same bg color and
' style for columns Sample # (AN) through S ICPO40B (0.01%) (CA)

' 6 = yellow 7 = purple -4142 = null/white

Sub SetRowUnifiedStyle()

For i = 2 To 15571

If Range("AN" & CStr(i)) <> 0 Then

Range("AN" & CStr(i) & ":CA" & CStr(i)).Interior.Color = Range("B" & CStr(i)).Interior.Color
Range("AN" & CStr(i) & ":CA" & CStr(i)).Interior.Pattern = Range("B" & CStr(i)).Interior.Pattern
Range("AN" & CStr(i) & ":CA" & CStr(i)).Borders(xlEdgeLeft).LineStyle = Range("B" & CStr(i)).Borders(xlEdgeLeft).LineStyle
Range("AN" & CStr(i) & ":CA" & CStr(i)).Borders(xlEdgeRight).LineStyle = Range("B" & CStr(i)).Borders(xlEdgeRight).LineStyle
Range("AN" & CStr(i) & ":CA" & CStr(i)).Borders(xlEdgeBottom).LineStyle = Range("B" & CStr(i)).Borders(xlEdgeBottom).LineStyle
Range("AN" & CStr(i) & ":CA" & CStr(i)).Borders(xlEdgeTop).LineStyle = Range("B" & CStr(i)).Borders(xlEdgeTop).LineStyle

End If

Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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