I'm attempting to change the color for a row based on the range from the cell value of "Actual" which is always in column B to the final column which is AX. I was attempting to calculate this in the LastCol line as I was not sure how to begin. at the moment the lastcol line is counting all columns which i understand. How can i limit this to my needed range?
Function Format()
Dim Rng, Rng2, cell, rngtocopy, rngtofinal As Range
Dim LastRow, LastCol As Long
Dim i As Long
Dim ws1 As Worksheet
Set ws1 = Sheets("Cost Sheet")
LastRow = ws1.Cells(ws1.Rows.Count, "B").End(xlUp).Row
LastCol = ws1.Cells(ws1.Columns.Count).End(xlRight).Column
Set Rng = ws1.Range("B12", ws1.Cells(LastRow, "B"))
Set Rng2 = ws1.Range(cell, cell & LastCol)
For Each cell In Rng
If cell.Value = "Actual" Then
cell.EntireRow.Locked = True
With cell
.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 12632256
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next cell
End Function