I'm trying to make a sub that copies and pastes a range of data and modifies some aspects of the formatting of the second range.
I want to make the color dependent on if the numbers are odd or even - here is what i wrote so far:
sub copy_paste_format()
Dim c As Variant
Dim SECONDARY()
Dim i As Integer
Dim n As Integer
ActiveCell.Offset(0, -5).Range("A1:E5").Select
ActiveWorkbook.Names.Add Name:="PRIMARY", RefersToR1C1:= _
"=Sheet2!R1C1:R5C5"
Selection.Copy
ActiveCell.Offset(0, 5).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Range("A1:E5").Select
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:="SECONDARY", RefersToR1C1:= _
"=Sheet2!R1C6:R5C10"
Selection.Font.Bold = True
With Selection.Font
.Name = "Calibri"
.Size = 14
End With
n = SECONDARY.Count
For i = 1 To n
If Cells.Value Mod 2 = 0 Then
Cells.Font.Color = vbRed
Else: Cells.Font.Color = vblue
End If
Next i
End Sub
The part I'm having trouble with is the color formatting. At the moment I'm getting a compile error of an "invalid qualifier". But using SECONDARY.count in the for loop doesn't produce any better results.
Does anyone have any suggestions?