Craigh4444
New Member
- Joined
- Jun 5, 2023
- Messages
- 2
- Office Version
- 2011
- Platform
- Windows
Good morning, i have written the VBA code below to move data from 1 sheet (Mastersheet) to another sheet (Audit Check 1) based on a column cell value and then highlight the blanks that occur in column F,
now i want write this code that will only highlight a cell if the value in column E matches the value i have in my code AND the value in column F is blank.
Private Sub CommandButton1_Click()
Sheets("Audit Check 1").Cells.Clear
Sheets("Audit Check 1").Cells.Interior.Color = xlNone
Dim i, Lastrow
Lastrow = Sheets("P6 Key Fields Layout").Range("A" & Rows.count).End(xlUp).Row
For i = 2 To Lastrow
If Sheets("P6 Key Fields Layout").Cells(i, "E").Value = ("PMS") Then
Sheets("P6 Key Fields Layout").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Audit Check 1").Range("A" & Rows.count).End(xlUp).Offset(1)
End If
Next i
Lastrow = Sheets("P6 Key Fields Layout").Range("A" & Rows.count).End(xlUp).Row
For i = 2 To Lastrow
If Sheets("P6 Key Fields Layout").Cells(i, "E").Value = ("SSR") Then
Sheets("P6 Key Fields Layout").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Audit Check 1").Range("A" & Rows.count).End(xlUp).Offset(1)
End If
Next i
Lastrow = Sheets("P6 Key Fields Layout").Range("A" & Rows.count).End(xlUp).Row
For i = 2 To Lastrow
If Sheets("P6 Key Fields Layout").Cells(i, "E").Value = ("HSR") Then
Sheets("P6 Key Fields Layout").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Audit Check 1").Range("A" & Rows.count).End(xlUp).Offset(1)
End If
Next i
Dim r As Range
Set r = Sheets("Audit Check 1").Range("F:F")
For Each cell In r
If cell.Value = "" Then
cell.Interior.ColorIndex = 6
End If
Next
MsgBox ("Audit Check Complete")
End Sub
now i want write this code that will only highlight a cell if the value in column E matches the value i have in my code AND the value in column F is blank.
Private Sub CommandButton1_Click()
Sheets("Audit Check 1").Cells.Clear
Sheets("Audit Check 1").Cells.Interior.Color = xlNone
Dim i, Lastrow
Lastrow = Sheets("P6 Key Fields Layout").Range("A" & Rows.count).End(xlUp).Row
For i = 2 To Lastrow
If Sheets("P6 Key Fields Layout").Cells(i, "E").Value = ("PMS") Then
Sheets("P6 Key Fields Layout").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Audit Check 1").Range("A" & Rows.count).End(xlUp).Offset(1)
End If
Next i
Lastrow = Sheets("P6 Key Fields Layout").Range("A" & Rows.count).End(xlUp).Row
For i = 2 To Lastrow
If Sheets("P6 Key Fields Layout").Cells(i, "E").Value = ("SSR") Then
Sheets("P6 Key Fields Layout").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Audit Check 1").Range("A" & Rows.count).End(xlUp).Offset(1)
End If
Next i
Lastrow = Sheets("P6 Key Fields Layout").Range("A" & Rows.count).End(xlUp).Row
For i = 2 To Lastrow
If Sheets("P6 Key Fields Layout").Cells(i, "E").Value = ("HSR") Then
Sheets("P6 Key Fields Layout").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Audit Check 1").Range("A" & Rows.count).End(xlUp).Offset(1)
End If
Next i
Dim r As Range
Set r = Sheets("Audit Check 1").Range("F:F")
For Each cell In r
If cell.Value = "" Then
cell.Interior.ColorIndex = 6
End If
Next
MsgBox ("Audit Check Complete")
End Sub