Thanks for your persistence Jim, and welcome to the party Ryan. Here is the
code, in it's entirety (maybe this will help or just make things more
confusing).
Sub LoopMac()
Dim lastRow As Long
Dim c As Variant
Dim sh As Worksheet
For Each sh In Worksheets
If (sh.Name) <> "C2_UnionQuery" And (sh.Name) <> "Summary-Sheet" Then
sh.Activate
With sh
Chng = Range("T6").Value
lastRow = .Cells(.Rows.Count, "T").End(xlUp).Row
For Each c In .Range("T6:T" & lastRow)
If c.Value <> "" Then
c.Offset(, 1).Formula =
"=IF(ISNUMBER(RC[-1]/RC[-9]),RC[-1]/RC[-9],""N/A"")"
End If
Next c
With sh
Chng = Range("U6").Value
lastRow = .Cells(.Rows.Count, "T").End(xlUp).Row
For Each c In .Range("T6:T" & lastRow)
If c.Value <> "" Then
c.Offset(, 2).Formula =
"=IF(ISNUMBER(RC[-1]/R2C21*R3C21),IF(RC[-1]/R2C21*R3C21>1,1,RC[-1]/R2C21*R3C21),""N/A"")"
End If
Next c
With sh
Chng = Range("X6").Value
lastRow = .Cells(.Rows.Count, "T").End(xlUp).Row
For Each c In .Range("T6:T" & lastRow)
If c.Value <> "" Then
c.Offset(, 4).Formula =
"=IF(ISNUMBER(RC[-2]),SUM(RC[-1],RC[-9])*RC[-2],0)"
End If
Next c
With sh
Chng = Range("Z6").Value
lastRow = .Cells(.Rows.Count, "T").End(xlUp).Row
For Each c In .Range("T6:T" & lastRow)
If c.Value <> "" Then
c.Offset(, 6).Formula =
"=IF(ISNUMBER(RC[-4]),RC[-2]+RC[-1]*RC[-4],0)"
End If
Next c
Range("W6:W" & Cells(Rows.Count,
"T").End(xlUp).Row).Interior.ColorIndex = 36
Range("Y6:Y" & Cells(Rows.Count,
"T").End(xlUp).Row).Interior.ColorIndex = 36
lastRow = .Cells(.Rows.Count, "T").End(xlUp).Row
.Cells(lastRow, "T").Activate
ActiveCell = .Cells(.Rows.Count, "W").End(xlUp).Row
.Cells(lastRow, "W").FormulaR1C1 _
= "=sum(r2c:r[-1]c)"
ActiveCell = .Cells(.Rows.Count, "X").End(xlUp).Row
.Cells(lastRow, "X").FormulaR1C1 _
= "=sum(r2c:r[-1]c)"
ActiveCell = .Cells(.Rows.Count, "Y").End(xlUp).Row
.Cells(lastRow, "Y").FormulaR1C1 _
= "=sum(r2c:r[-1]c)"
ActiveCell = .Cells(.Rows.Count, "Z").End(xlUp).Row
.Cells(lastRow, "Z").FormulaR1C1 _
= "=sum(r2c:r[-1]c)"
Range("T6:Z6").AutoFill Destination:=Range(Range("T6"),
Cells(lastRow, "Z"))
Columns("U:V").Select
Selection.NumberFormat = "0%"
End With
End With
End With
End With
End If
Next sh
End Sub
Just to clarify things, I am trying to select all cells in Column T that
contain data, and fill to the right, including Column Z, with the formatting
in Column T. I can't use any kind of ctrl+end, or used range, because
several tables that I am doing these operation on are coming from a large
Pivot Table which is filtered for certain elements, and then copied/pasted to
several sheets that I create on the fly. All of this is working except for
getting the formatting in Column T to fill-right.
Appreciate all your help up to this point and any help forthcoming.
Regards,
Ryan---
--
RyGuy
RyanH said:
Try this. This will copy you selection to the adjacent 4 columns.
Selection.AutoFill Destination:=Range("T6:AB" & LastRow),
Type:=xlFillDefault
Hope this helps!