Loop formula for Dynamic range

niggszo

New Member
Joined
Aug 24, 2011
Messages
5
have this data on a spreadsheet which I format with a recorded macro but Both the rows and columns change frequently everyday and the macro only works for the cells I recorded . How Do I create a dynamic range and loop the formula to customize the newer and additional rows and columns
i.e add more rows for more teams and for the rest of the month.

the Rows are
Jan 1 Jan 2 Jan 3
Concorde Score 160 160 80
Total 0 134 63
%age 0 0.8375 0.7875

Victoria 120 100 50
Code:
Sub Test3w()
'
' Test3w Macro
'

'
    Columns("A:A").Select
    Selection.Delete Shift:=xlToLeft
    Range("A4").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Rows("3:4").Select
    Range("A4").Activate
    Selection.Delete Shift:=xlUp
    Columns("C:C").Select
    Selection.Delete Shift:=xlToLeft
    Range("B5").Select
    ActiveCell.FormulaR1C1 = ""
    Range("B3").Select
    ActiveCell.FormulaR1C1 = "Score"
    Range("B4").Select
    ActiveCell.FormulaR1C1 = "T"
    Range("B4:C5").Select
    ActiveCell.FormulaR1C1 = "Total "
    Range("B5").Select
    ActiveCell.FormulaR1C1 = "%age"
    Range("C5").Select
    ActiveCell.FormulaR1C1 = "=IF(R[-2]C=0,""no Score"",R[-1]C/R[-2]C)"
    Range("C5").Select
    Selection.AutoFill Destination:=Range("C5:E5"), Type:=xlFillDefault
    Range("C5:E5").Select
    Range("C5").Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
        Formula1:="=0", Formula2:="=0.5"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16383844
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13551615
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Range("C5:E5").Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
        Formula1:="=0.05", Formula2:="=0.001"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Range("C5:E5").Select
    Selection.Copy
    Range("C21:E21,C9:E9,C13:E13,C17:E17,C25:E25").Select
    Range("C25").Activate
    ActiveWindow.ScrollRow = 2
    ActiveWindow.ScrollRow = 5
    ActiveWindow.ScrollRow = 7
    ActiveWindow.ScrollRow = 9
    ActiveWindow.ScrollRow = 12
    ActiveWindow.ScrollRow = 13
    ActiveWindow.ScrollRow = 15
    ActiveWindow.ScrollRow = 17
    ActiveWindow.ScrollRow = 19
    ActiveWindow.ScrollRow = 20
    ActiveWindow.ScrollRow = 21
    ActiveWindow.ScrollRow = 22
    ActiveWindow.ScrollRow = 23
    Range( _
        "C21:E21,C9:E9,C13:E13,C17:E17,C25:E25,C29:E29,C33:E33,C37:E37,C41:E41,C45:E45,C49:E49" _
        ).Select
    Range("C49").Activate
    ActiveWindow.SmallScroll Down:=-18
    Selection.PasteSpecial Paste:=xlPasteFormulasAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    ActiveWindow.SmallScroll Down:=-3
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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