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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
not sure what exactly you are looking to do? do you simply want to put a border around each group of values in column A to visually separate them or something more complex?
 
Upvote 0
not sure what exactly you are looking to do? do you simply want to put a border around each group of values in column A to visually separate them or something more complex?

Correct, I want 2 visually separate each data set
 
Upvote 0
1. Select cell A1
2. Hold Control + Shift and press right arrow
3. Hold Control + Shift and press down arrow
4. Right click cells and go to format cells
5. Select border tab
 
Upvote 0
how about this.

Code:
Sub Underline()
 'Add Border
For r = 7 To 29
Range(Cells(r, "A"), Cells(r, "K")).Borders(xlEdgeBottom).LineStyle = xlNone
If Cells(r, "A") <> Cells(r - 1, "A") Then Range(Cells(r - 1, "A"), Cells(r - 1, "K")).Borders(xlEdgeBottom).Weight = xlMedium
Next r

End Sub

Ross
 
Upvote 0
Thanks, i cleaned it up a bit.

Code:
Sub Underline()

    Dim i As Long
    Dim LR As Long
    
    With Sheets(1)
        LR = Range("A" & Rows.Count).End(xlUp).Row
        For i = 6 To LR
            .Range(.Cells(i, "A"), .Cells(i, "K")).Borders(xlEdgeBottom).LineStyle = xlNone
            If .Cells(i, "A") <> .Cells(i - 1, "A") Then .Range(.Cells(i - 1, "A"), .Cells(i - 1, "K")).Borders(xlEdgeBottom).Weight = xlMedium
        Next i
    End With

End Sub
 
Upvote 0
This does not work if couple of columns is blank, can the code workout the header row which is row 5, i need the line to go as far as the end column of last header column

LC = Range("IV1").End(xlToLeft).Column
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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