VBA draw table line borders every 18 count

harky

Active Member
Joined
Apr 8, 2010
Messages
288
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:

salim hasan

Board Regular
Joined
Dec 25, 2013
Messages
103
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:

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
42,304
Office Version
365
Platform
Windows
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
 

harky

Active Member
Joined
Apr 8, 2010
Messages
288
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
 

harky

Active Member
Joined
Apr 8, 2010
Messages
288
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:

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
42,304
Office Version
365
Platform
Windows
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
 

harky

Active Member
Joined
Apr 8, 2010
Messages
288
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
 

salim hasan

Board Regular
Joined
Dec 25, 2013
Messages
103
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:

Forum statistics

Threads
1,082,385
Messages
5,365,151
Members
400,825
Latest member
Sreekanth_21

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top