VBA help

Donai

Well-known Member
Joined
Mar 28, 2009
Messages
543
Hi, i am after a vba code that will look at column A and put a thick black line accross each data set. I think this is the best way to split the data?


Excel Workbook
ABCDEFGHIJK
5GroupHeader2Header3Header4Header5Header6Header7Header8Header9Header10Header11
6NOMSDataDataDataDataDataDataDataDataDataData
7NOMSDataDataDataDataDataDataDataDataDataData
8NOMSDataDataDataDataDataDataDataDataDataData
9NOMSDataDataDataDataDataDataDataDataDataData
10NOMSDataDataDataDataDataDataDataDataDataData
11NOMSDataDataDataDataDataDataDataDataDataData
12LIFEDataDataDataDataDataDataDataDataDataData
13LIFEDataDataDataDataDataDataDataDataDataData
14LIFEDataDataDataDataDataDataDataDataDataData
15LIFEDataDataDataDataDataDataDataDataDataData
16LIFEDataDataDataDataDataDataDataDataDataData
17LIFEDataDataDataDataDataDataDataDataDataData
18LIFEDataDataDataDataDataDataDataDataDataData
19LIFEDataDataDataDataDataDataDataDataDataData
20LIFEDataDataDataDataDataDataDataDataDataData
21LIFEDataDataDataDataDataDataDataDataDataData
22LIFEDataDataDataDataDataDataDataDataDataData
23LIFEDataDataDataDataDataDataDataDataDataData
24CITICASHDataDataDataDataDataDataDataDataDataData
25CITICASHDataDataDataDataDataDataDataDataDataData
26CITICASHDataDataDataDataDataDataDataDataDataData
27CITICASHDataDataDataDataDataDataDataDataDataData
28CITICASHDataDataDataDataDataDataDataDataDataData
29CITICASHDataDataDataDataDataDataDataDataDataData
Sheet1
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hiker i want to use this code over two worksheets, i tried Sheets(Array, but the code fails.

Code:
Sub UnderlineAssets()
    Dim i As Long
    Dim LR As Long
    
    With Sheets(Array("Cash", "Asset"))
        LR = .Range("A" & Rows.Count).End(xlUp).Row
        LC = Cells(5, Columns.Count).End(xlToLeft).Column
        For i = 6 To LR
'            .Range(.Cells(i, "A"), .Cells(i, "U")).Borders(xlEdgeBottom).LineStyle = xlNone
            If .Cells(i, "A") <> .Cells(i - 1, "A") Then .Range(.Cells(i - 1, "A"), .Cells(i - 1, LC)).Borders(xlEdgeBottom).Weight = xlMedium
        Next i
    End With
End Sub
 
Upvote 0
Donai,

The following codes seems to work correctly with your posted screenshot.


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Code:
Option Explicit
Sub UnderlineAssets()
Dim i As Long
Dim LR As Long, LC As Long
Dim ws As Worksheet
For Each ws In Worksheets(Array("Cash", "Asset"))
  With ws
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    LC = .Cells(5, Columns.Count).End(xlToLeft).Column
    For i = 6 To LR
'            .Range(.Cells(i, "A"), .Cells(i, "U")).Borders(xlEdgeBottom).LineStyle = xlNone
      If .Cells(i, "A") <> .Cells(i - 1, "A") Then .Range(.Cells(i - 1, "A"), .Cells(i - 1, LC)).Borders(xlEdgeBottom).Weight = xlMedium
    Next i
  End With
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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