I am not very good with VBA in excel.
I have this code below that I use in excel, works fine with one drawback that I repeat it for each worksheet because each worksheet has a different name.
Is it possible in excel to use global code for more that one worksheet without having to repeat the code?
What I want to do is draw a border around cells. Like Row 6 Column A to J using the code below.
I would appreciate any help.![]()
Sub DoTheLot() 'Borders Dim R As Long 'R represents ROWS, Dim R_From As Long Dim R_To As Long Dim LastCol As Long R_From = 5 With Sheets("KOLETSIS") R_To = .Cells(.Rows.Count, "J").End(xlUp).Row For R = R_From To R_To LastCol = .Cells(R, .Columns.Count).End(xlToLeft).Column Select Case Cells(R, "J").Value Case "Out of Order" .Cells(R, "A").Resize(, LastCol).Font.ColorIndex = 3 'Red Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With Selection.Borders(xlInsideVertical).LineStyle = xlNone End Select Next R End With End Sub
Many thanks
Bookmarks