How to Dynamically fill the borders in excel

I have used vba code to fill the borders in excel and I have assigned a variable to the Range but it is showing an error. Is there a way where we can dynamically add borders in excel

HI @Jyothi_SUVERA

Can you send the screenshot of error?

Regards
Sudharsan

Hello @Jyothi_SUVERA
Try this VBA code

Function ApplyCellBorderActiveCells(sheetName As String) As String
    On Error GoTo ErrorHandler
    For Each cell In Sheets(sheetName).UsedRange
        If cell.Text = vbNullString Then GoTo SkipCell
        With cell.Borders
            .LineStyle = xlContinuous
            .Color = xlBlack
        End With
SkipCell:
    Next cell
    ApplyCellBorderActiveCells = "Success"
    Exit Function
ErrorHandler:
    Debug.Print Err.Description
    ApplyCellBorderActiveCells = "Error: " & Err.Description
End Function