VBA coding needed please

LadyHarper

Board Regular
Joined
Jun 28, 2017
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Good Morning,

I need to write a VBA coding for a conditional formatting

Formula =$A1<>$A2 Applies to $A:$M

It's so that it adds Lines as I am adding rows when Column A is different. The problem with conditional formatting is when you insert a line, as something was missed it breaks up the formula and I need it to stay the same.
 

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
Try:

VBA Code:
Sub Macro1()
  Cells.FormatConditions.Delete
  With Range("A:M")         'Adjust the range as you wish
    .FormatConditions.Add xlExpression, , "=$A1<>$A2"
    .FormatConditions(1).Interior.Color = vbYellow
  End With
End Sub
 
Upvote 0
1728498971825.png

I added this in and it is not creating the lines.
 
Upvote 0
It's highlighting stuff, I need it to automatically add a line under the row, when the number changes in column A

I am continuously adding rows, and need it to automatically add the line, without running the marco
 
Last edited:
Upvote 0
Ok so I am adding rows, and when Column A changes to something different, I need it to add a bottom border line. Like when you create lines around a cell, it to create the line, across A to M.

and it to automatically add this line, as I work, and not have to go in and run a macro.

So if row 1, 2 and 3, all have the number 1 in column A then the line would appear after row 3, and then row 4, 5 and 6 all have the number 4 in column A, the line appears after row 6.

the above formula, $A1<>$A2 tells it to apply the formatting to $A:$M.

But I don't know how to write a VBA script to make it do it automatically, and to create the bottom border Line.

Your code highlights instead of creating the cell bottom boarder line, and I have to tell it to run the macro to do it, the code needs to be automatic,
 
Upvote 0
1729696756263.png

Still looking for VBA coding that can have excel do this automatically, as in the conditional formatting, if I delete or add a line, it changes the applies to, and I need it to always stay the same.
 
Upvote 0
The following code will be executed automatically every time you modify a cell in column A, even if you add a new row or delete one or more rows.


Put the following code in Sheet Event:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rng As Range

  Set rng = Intersect(Target, Range("A:A"))
  If Not rng Is Nothing Then
    Cells.FormatConditions.Delete
    With Range("A:M")         'Adjust the range as you wish
      .FormatConditions.Add xlExpression, , "=$A1<>$A2"
      .FormatConditions(1).Borders(xlBottom).LineStyle = xlContinuous
    End With
  End If
End Sub
Note Sheet Event:
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.

----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

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