How do you set Excel borders on certain columns?

I have an excel template which will later be filled in from a CSV file, then the CSV data will be copied to Excel in columns “A8:C8” including headers, but the amount of data will always change.

So how do you ensure that every data that has been copied to Excel will continue to border the data?

@Kia1

You need to use vba to set borders

Cheers

1 Like

Yes, I’ve seen it
is it ok to see the workflow in UiPath? is it necessary to use “Assign”?

@Kia1

This is a vba …a macro code …you need to save it in a text file and use invoke vba method/code activity to run it on an excel once the data is filled

Cheers

1 Like


Yes, have followed the Vba invoke

But why are the empty rows and columns in the border?
Is my code wrong?
What is certain is that later the data will increase downwards, not sideways

Sub HighlightFilledRows()
Dim ws As Worksheet
Dim lastRow As Long
Dim rng As Range
Dim cell As Range

' Specify the worksheet name
Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name

' Find the last row with data in column A
lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row

' Loop through each row and check if it's filled
For Each rng In ws.Range("A8:C8" & lastRow)
    If WorksheetFunction.CountA(rng.EntireRow) > 0 Then
        ' Highlight the row if it's filled with a black border
        rng.EntireRow.Borders.LineStyle = xlContinuous
        rng.EntireRow.Borders.Color = RGB(0, 0, 0) ' Black color
    Else
        ' Remove borders if the row is not filled
        rng.EntireRow.Borders.LineStyle = xlNone
    End If
Next rng

End Sub

@Kia1

As per code it does entire row…if you need only for a range then you need to change accordingly

This works for filled range

Cheers

1 Like

@Kia1

It takes sheetname as input…please add as parameter

Cheers

1 Like

where should I add parameters? what sheet name should be used?

@Kia1

In invoke vba you would have parameters option…add one and give the sheetname where you need to boarders

Cheers