VBA draw table line borders every 18 count

harky

Active Member
Joined
Apr 8, 2010
Messages
405
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
I not sure if it possible?

VBA draw table line border every 18 count from col T to AF


COL TCOL UCOL VCOL WCOL XCOL YCOL ZCOL AACOL ABCOL ACCOL ADCOL AECOL AF
ROW1ABCDEFFGHADDG
ROW21234567
ROW3121019
ROW41237
ROW545678910
ROW65350

<tbody>
</tbody>



So row 1 & 2 is add up is 20 count.
It will draw a table border below

Row 4, 5, 6 add up is 18 count
It will draw a table border below
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
whKE0OP.png
 
Upvote 0
Try this macro
Code:
Option Explicit


Sub Special_Borders()
 Dim Ar, Sub_Ar
 Cells(2, "T").Resize(20, 13).Borders.LineStyle = 0
 Ar = Array(2, 6, 8, 12, 14, 20)
 For Each Sub_Ar In Ar
    With Cells(Sub_Ar, "T").Resize(, 13).Borders(9)
     .LineStyle = 1
     .Weight = 4
    End With
 Next


End Sub
 
Last edited:
Upvote 0
Give this a try
Code:
Sub Line_After_Every_18()
  Dim a As Variant
  Dim i As Long, j As Long, k As Long, uba2 As Long
  
  a = Range("T1", Range("T" & Rows.Count).End(xlUp)).Resize(, 13).Value
  uba2 = UBound(a, 2)
  For i = 1 To UBound(a)
    For j = 1 To uba2
      If Len(a(i, j)) Then k = k + 1
      If k = 18 Then
        Range("T" & i).Resize(, 13).Borders(xlEdgeBottom).LineStyle = xlContinuous
        k = 0
        Exit For
      End If
    Next j
  Next i
End Sub
 
Upvote 0
this only do top few row?

but i had thousand row with data.

Try this macro
Code:
Option Explicit


Sub Special_Borders()
 Dim Ar, Sub_Ar
 Cells(2, "T").Resize(20, 13).Borders.LineStyle = 0
 Ar = Array(2, 6, 8, 12, 14, 20)
 For Each Sub_Ar In Ar
    With Cells(Sub_Ar, "T").Resize(, 13).Borders(9)
     .LineStyle = 1
     .Weight = 4
    End With
 Next


End Sub
 
Upvote 0
yes this!!

but can i start from T22 row? as Row 1 to 21 is so call header.

Can change the line to thicker type?



Give this a try
Code:
Sub Line_After_Every_18()
  Dim a As Variant
  Dim i As Long, j As Long, k As Long, uba2 As Long
  
  a = Range("T1", Range("T" & Rows.Count).End(xlUp)).Resize(, 13).Value
  uba2 = UBound(a, 2)
  For i = 1 To UBound(a)
    For j = 1 To uba2
      If Len(a(i, j)) Then k = k + 1
      If k = 18 Then
        Range("T" & i).Resize(, 13).Borders(xlEdgeBottom).LineStyle = xlContinuous
        k = 0
        Exit For
      End If
    Next j
  Next i
End Sub
 
Last edited:
Upvote 0
but can i start from T22 row?
Yes, make these 2 changes
Rich (BB code):
 a = Range("T22", Range("T" & Rows.Count).End(xlUp)).Resize(, 13).Value

        Range("T" & i + 21).Resize(, 13).Borders(xlEdgeBottom).LineStyle = xlContinuous
 
Upvote 0
Thanks!

Yes, make these 2 changes
Rich (BB code):
 a = Range("T22", Range("T" & Rows.Count).End(xlUp)).Resize(, 13).Value

        Range("T" & i + 21).Resize(, 13).Borders(xlEdgeBottom).LineStyle = xlContinuous
 
Upvote 0
Same macro with variable range
Code:
Option Explicit


Sub test()
Dim i%, k%, Arr(), Sub_Arr
k = 1
Const my_max = 50 [SIZE=2][COLOR=#ff0000]'change to wanted number[/COLOR][/SIZE]
For i = 1 To 10000
    ReDim Preserve Arr(1 To k)
    If i = 1 Then
     Arr(i) = 2
    Else
     Arr(i) = IIf(k Mod 2 = 1, Arr(i - 1) + 2, Arr(i - 1) + 4)
    End If
 If Arr(i) > my_max Then Exit For
     k = k + 1
 Next
 Cells(2, "T").Resize(20, 10000).Borders.LineStyle = 0
 For Each Sub_Arr In Arr
    With Cells(Sub_Arr, "T").Resize(, 13).Borders(9)
     .LineStyle = 1
     .Weight = 4
    End With
 Next
End Sub
Erase Arr
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,192
Members
448,554
Latest member
Gleisner2

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