Format Cells on Change Event

julhs

Active Member
Joined
Dec 3, 2018
Messages
471
Office Version
  1. 2010
Platform
  1. Windows
I know my Change Event code completely lacks the necessary code to format any cells, but that is part I’m struggling with.
The Xl2bb should be able demonstrate far better than I can explain as to what it is I’m trying to achieve.
In a nut shell; if you insert cells in say B10:C10 it leaves the last cell in ColA without any formatting but I want it formatted
the same as last cell ColA -1.
Test Insert.xlsm
ABCDE
5
6This Range of cells can NOT have cells inserted into itDataDataWhen I manually insert cells in B6:C23 and use "Shift Down", I also want to automatically format A30+1 to take into account the new extended range B6:C24.
7DataData
8DataData
9DataData
10DataData
11DataData
12DataData
13DataData
14DataData
15DataData
16DataData
17DataData
18DataData
19DataData
20DataData
21DataData
22DataData
23DataData
24DataDataOf coarse if I manually insert cells in A25:C30, the new cells are formated to the same as cells above
25DataData
26DataData
27DataData
28DataData
29DataData
30DataData
31
Sheet1
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Would help if I includede the Change Event
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Application.EnableEvents = False
    If Not Intersect(Target, Range("Chem_Test")) Is Nothing Then
     ActiveSheet.[$A$30].Select
  End If
   Application.EnableEvents = True
End Sub
 
Upvote 0
Give me strength!!
"Chem_Test" is named range "Sheet1!$B$6:$C$30"
 
Upvote 0
If it’s of any help to someone in the future I eventually came up with something that did what I wanted.
Don’t doubt a more capable person would be able to come up with something more concise.

Test Insert.xlsm
ABCDE
5
6Array formula hereDataData
7Array formula hereDataDataWhen I manually insert cells in B6:C23 and use "Shift Down", I also want to automatically format A30+1 to take into account the new extended range B6:C30+1.
8Array formula hereDataData
9Array formula hereDataData
10Array formula hereDataData
11Array formula here
12Array formula here
13Array formula here
14Array formula hereDataData
15Array formula here
16Array formula hereDataData
17Array formula hereDataData
18Array formula here
19Array formula hereDataData
20Array formula here
21Array formula hereDataData
22Array formula hereDataData
23Array formula hereDataData
24Of coarse if I manually insert cells in A25:C30, the new cells are formated to the same as cells above
25
26DataData
27
28
29DataData
30DataData
31
Sheet1

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim LastRow As Long
 Dim rng As Range
        Application.ScreenUpdating = False
        Application.EnableEvents = False   
  If Not Intersect(Target, Range("Chem_Test")) Is Nothing Then
     LastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, _
                 SearchDirection:=xlPrevious).Row
      Call ReFormatRange  'Is in this Module
    End If
  If Not Intersect(Target, Range("ArrayFormula")) Is Nothing Then
     LastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, _
                 SearchDirection:=xlPrevious).Row
      Call ReFormatRange  'Its in this Module
    End If
  Set rng = Range("A" & LastRow + 1)
   rng.Select
        Application.ScreenUpdating = True
        Application.EnableEvents = True
End Sub
'---------------------------------------------------------------------------------
Sub ReFormatRange()
 Dim LastRow As Long
 Dim LastRow1 As Long
        Application.ScreenUpdating = False
'----
'# This finds LastRows and then "ReFormats" ColA to Lastrow1(ColB)if rows are ADDED or DELETED in B6:C25
   With ActiveSheet
     LastRow1 = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, _
                  SearchDirection:=xlPrevious).Row
     LastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, _
                 SearchDirection:=xlPrevious).Row
     LastRow = ActiveSheet.Range("A40").End(xlUp).Row 'was LastRow1
      .Range("A" & LastRow1 & ":A" & LastRow + 1).Select
        Selection.FillDown
'----
'# This "ReFormats" (LastRow1 ColA:LastRow1 ColC) down if rows are DELETED in ColB:ColC
'#   it will ALSO reformat ColA if "ArrayFormula" NamedRange has rows INSERTED or DELETED
      .Range("A" & LastRow1 + 1 & ":C" & LastRow1 + 5).Select
        With Selection.Interior
           .Pattern = xlNone
           .TintAndShade = 0
           .PatternTintAndShade = 0
    End With
'----
'# This "ReFormats" ColA if a row is INSERTED immediatly below "ArrayFormula" NamedRange
'#   ,ie "ArrayFormula" NamedRange +1
      .Range("A" & LastRow + 1 & ":A" & LastRow1).Select
        With Selection.Interior
           .Pattern = xlSolid
           .PatternColorIndex = xlAutomatic
           .ThemeColor = xlThemeColorAccent3
           .TintAndShade = 0.599993896298105
           .PatternTintAndShade = 0
        With Selection.Font
           .ColorIndex = xlAutomatic
           .TintAndShade = 0
   End With
  End With
 End With
        Application.ScreenUpdating = True
End Sub
 
Upvote 0
NamedRanges
"ArrayFormula" =Sheet1!$A$6:$A$23
"Chem_Test" =Sheet1!$B$6:$C$30
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,702
Members
452,667
Latest member
vanessavalentino83

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