adding border line after the same id number

dankar

Board Regular
Joined
Mar 23, 2016
Messages
113
Office Version
  1. 365
Platform
  1. Windows
ID number
B
C
D
E
F
1
109094
2
109094
3
148877
4
148877
5
154470
6
154470
7
154470
8
154470
9
183357

<tbody>
</tbody>


I have 566 row and more than 10 columns
I have multiple id numbers.
I want to split the id numbers with a border line (the whole raw)

so as the example table:

I want t have a border line
after number 2
after number 4
after number 8
after number 9

the id number could be only one (unique) ,or 2 same numbers or 3 same number or 4 same number etc.

is there way (code) to do it,,thank you
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
do you mean a border where there is a duplicate, you could do that with a conditional format
 
Upvote 0
How about
Code:
Sub AddBorder()
   Dim Cl As Range
   For Each Cl In Range("A2", Range("A" & Rows.count).End(xlUp))
      If Cl.Value <> Cl.Offset(1).Value Then Cl.Resize(, 10).Borders(xlEdgeBottom).Weight = xlMedium
   Next Cl
End Sub
 
Upvote 0
How about
Code:
Sub AddBorder()
   Dim Cl As Range
   For Each Cl In Range("A2", Range("A" & Rows.count).End(xlUp))
      If Cl.Value <> Cl.Offset(1).Value Then Cl.Resize(, 10).Borders(xlEdgeBottom).Weight = xlMedium
   Next Cl
End Sub

Thank you a lot, worked perfectly!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Dankar,

This will underline from A to K but you can change K to get a larger or a smaller line:

Good luck!
George


Sub row_underline_1()

For i = 0 To 1000000
If ([B2].Offset(i, 0) = [B2].Offset(i + 1, 0)) = False Then [A2:K2].Offset(i, 0).Borders(xlEdgeBottom).Weight = xlThick
If [B2].Offset(i, 0) = "" Then Exit For
Next i

End Sub
 
Last edited by a moderator:
Upvote 0
For those who might be interested, here is a way to do what the OP wants without using any loops at all...
Code:
[table="width: 500"]
[tr]
	[td]Sub AddBorderBottomBorders()
  With Range("A2", Cells(Rows.Count, "A").End(xlUp))
    .Formula = Evaluate(Replace("IF(@<>" & .Offset(1).Address & ",""=""&@,@)", "@", .Address))
    Intersect(.SpecialCells(xlFormulas).EntireRow, Columns("A:J")).Borders(xlEdgeBottom).Weight = xlMedium
    Intersect(.SpecialCells(xlFormulas).EntireRow, Columns("A:J")).Borders(xlInsideHorizontal).Weight = xlMedium
    .Replace "=", "", xlPart, , , , False, False
  End With
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,225
Members
448,877
Latest member
gb24

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