Hi, I wonder whether someone could help me please.
I've put together the following code which applies formatting to a given sheet.
Sub UniqueRecordsABFormat()
Dim cell As Range
Dim i As Long
Dim LastRow As Long
Dim LR As Long
Dim MyNames As Variant
Application.ScreenUpdating = False
Sheets("Unique Records AB").Select
Const StartRow As Long = 8
Set Data = Range("E8:P" & Range("B" & Rows.Count).End(xlUp).Row)
With Range("B2")
.Value = "Current Month"
End With
With Range("B3")
.Value = Format(Date, "1 mmm yy")
.NumberFormat = "mmm yy"
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 37
With .Font
.Name = "Lucida Sans"
.Bold = True
.Size = 10
End With
End With
With Range("B2, B5")
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 11
With .Font
.Name = "Lucida Sans"
.Bold = True
.Size = 11
.ColorIndex = 2
End With
End With
With Range("B7:R7")
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 37
With .Font
.Name = "Lucida Sans"
.Bold = True
.Size = 10
End With
End With
For Each cl In Data
If cl.Value = 0 Then
cl.Value = ""
End If
Next cl
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
If LastRow >= StartRow Then
With Range("B8:R" & LastRow)
With .Font
.Name = "Lucida Sans"
.Size = 10
End With
End With
With Range("E8:P" & LastRow)
.HorizontalAlignment = xlCenter
.NumberFormat = "#,##0.00"
.Value = Application.Round(.Value, 2)
End With
With Range("B8:R" & LastRow)
.Sort Key1:=.Cells(1, 1), Order1:=xlAscending, Key2:=.Cells(1, 2), order2:=xlAscending
End With
End If
For Each cell In Range("R8", Range("B" & Rows.Count - 1).End(xlUp)).Cells
If cell.Value = "" Then
cell.Value = "Fixed Resource"
End If
Next cell
For Each cell In Range("E8:P8", Range("B" & Rows.Count - 1).End(xlUp)).Cells
If cell.Value = 0 Then
cell.Value = ""
End If
Next cell
Columns("B:R").AutoFit
End Sub
The code works, except for this section:
For Each cell In Range("R8", Range("B" & Rows.Count - 1).End(xlUp)).Cells
If cell.Value = "" Then
cell.Value = "Fixed Resource"
End If
Next cell
What I'm trying to do is add the word "Fixed Resource" if any of the cells in column R, are emtpy.
This works, but the problem is that it also applies the same value to the cells in column Q and I'm not sure why.
I just wondered whether someone could possibly look at this please and let me know where I'm going wrong?
Many thanks and kind regards
Chris
Bookmarks