Inconsistent behaviour with conditional format ranges!

bobhasnoidea

New Member
Joined
Apr 9, 2019
Messages
8
So....
I have a number of conditional formats on a table and a macro that adds a number of new rows to the end my table, drops in text and R1C1 formulas etc,etc. So far so good!

When I run this macro some of conditional formats extend their range, and others don't! In the attached images I would like (and expect) all of the ranges to have increased from $30 to $37!

For the top two conditions it just creates new rules as $A$31:$A$37 but places them at the bottom, so the precedent orders are incorrect (as well as growing the number of conditional format rules)

If it is relevant, the rules are:
Formula =$A8<>$A9
Formula=MOD($A8,2)=1

Any pointers gratefully received as I've already spent an unacceptable amount of time swearing at my laptop!

Thank you!

2022-07-22 18_51_30-Clipboard.png
 

Attachments

  • 2022-07-22 19_00_38-CS1XX - Concrete Cube Register.xlsm - Excel.png
    2022-07-22 19_00_38-CS1XX - Concrete Cube Register.xlsm - Excel.png
    14.3 KB · Views: 5

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Please show the code for your macro, and tell us what columns the table is in. I suggest that after you paste the code into your post you select it and click the VBA button to format it.
 
Upvote 0
Please show the code for your macro, and tell us what columns the table is in. I suggest that after you paste the code into your post you select it and click the VBA button to format it.
Thanks Jeff, I'm a real VBA novice so it won't be pretty, but has got me where I needed (apart from this bit!!)


VBA Code:
Sub New_Group()

'----- Add Group Number
Dim result As String
    result = InputBox("Add Group Number", "Title") 'The variable is assigned the value entered in the InputBox
'----- Add 6 New Lines
Dim ws As Worksheet
    Set ws = Sheets("Cube Register")
    Dim tbl As ListObject
    Set tbl = ws.ListObjects("Cube_Register")
    Dim NewRow As ListRow
'----- Line 1
Set NewRow = tbl.ListRows.Add
    With NewRow
        .Range(1, ws.Range("Cube_Register[Group No.]").Column) = (result)
    End With
'----- Line 2
Set NewRow = tbl.ListRows.Add
    With NewRow
        .Range(1, ws.Range("Cube_Register[Group No.]").Column) = (result)
    End With
'----- Line 3
Set NewRow = tbl.ListRows.Add
    With NewRow
        .Range(1, ws.Range("Cube_Register[Group No.]").Column) = (result)
    End With
'----- Line 4
Set NewRow = tbl.ListRows.Add
    With NewRow
        .Range(1, ws.Range("Cube_Register[Group No.]").Column) = (result)
    End With
'----- Line 5
Set NewRow = tbl.ListRows.Add
    With NewRow
        .Range(1, ws.Range("Cube_Register[Group No.]").Column) = (result)
    End With
'----- Line 6
Set NewRow = tbl.ListRows.Add
    With NewRow
        .Range(1, ws.Range("Cube_Register[Group No.]").Column) = (result)
    End With
'----------------
Dim LR As Long
  'For understanding LR = Last Row

  LR = Cells(Rows.Count, 1).End(xlUp).Row
        ActiveSheet.Cells(LR, 18).Select
        ActiveCell.FormulaR1C1 = "=COUNTIF(R[0]C[-4]:R[-5]C[-4],"">0"")"
            ActiveSheet.Cells(LR, 19).Select
            ActiveCell.FormulaR1C1 = "=IF(R[0]C[-1]=2,R[-5]C[-13]+1,IF(R[0]C[-1]=3,R[-5]C[-13]+1,IF(R[0]C[-1]=4,R[-5]C[-13]+1,IF(R[0]C[-1]=5,R[-5]C[-13]+2,IF(R[0]C[-1]=6,R[-5]C[-13]+2,""err"")))))"
                ActiveSheet.Cells(LR, 20).Select
                ActiveCell.FormulaR1C1 = "=IF(R[0]C[-2]>0,Sum(R[0]C[-6]:R[-5]C[-6])/R[0]C[-2],""n/a"")"
'----- Adjust Print Area
 Dim sh As Worksheet
 Set sh = ActiveSheet
    Dim LstRw As Long, Rng As Range

        With sh
            LstRw = .Cells(.Rows.Count, "T").End(xlUp).Row
            Set Rng = .Range("A1:T" & LstRw)
            .PageSetup.PrintArea = Rng.Address
        End With
End Sub

Thanks again!
 
Upvote 0
I don't see anything obvious in the code. I'll have to mock this up to see if I can troubleshoot it. You would save me some steps if you have a way to share your file.
 
Upvote 0
Hi Jeff, I have actually sorted this today. Not sure what was going on to be honest. I deleted all my conditional formats and rebuilt them one by one, checking at each stage and luckily (typically) they all work as expected.

Really appreciate all your help!!
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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