adding border line after the same id number

dankar

Board Regular
Joined
Mar 23, 2016
Messages
113
Office Version
  1. 365
Platform
  1. Windows
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]ID number
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]109094
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]109094
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]148877
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]148877
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]154470
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]154470
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD]154470
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD]154470
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9
[/TD]
[TD]183357
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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