Мне нужно переформатировать строки, в которых есть строка «Без действия» в столбце C
Я использую это:
Dim ActionRow as Long
For ActionRow = 2 To 50
If .Cells(ActionRow, 3).Value = "No Action" Then
.Range("A" & ActionRow & ":AB" & ActionRow).Font.Italic = True
.Range("A" & ActionRow & ":AB" & ActionRow).Font.Color = 8421504
End If
Next ActionRow
Вместо того, чтобы просто нацеливать строки с «Без действия»в столбце C это предназначается для каждой строки, или отслеживает это непоследовательно.Как я могу сказать, чтобы только найти строку «Без действия» в столбце C (3), а затем выполнить форматирование?
Остальная часть кода:
Option Explicit
Sub Main()
Dim Wb As Workbook
Dim Data, Last, BU7, Lvl7
Dim sourcerow As Long, sourcecol As Long, destrow As Long, destcol As Long
Dim rngDest As Range
Dim ActionRow As Long
'Refer to the template
Set Wb = Workbooks("Book1.xlsx")
'Refer to the destination cell
Set rngDest = Wb.Sheets("Sheet1").Range("A2")
'Read in all data
With ThisWorkbook.Sheets("Data_")
Data = .Range("Ab2", .Range("A" & Rows.Count).End(xlUp))
End With
Wb.Activate
Application.ScreenUpdating = False
'Process the data
For sourcerow = 1 To UBound(Data, 1)
'Manager changes?
If Data(sourcerow, 15) <> Last Then
'Skip the first
If sourcerow > 1 Then
'Scroll into the view
rngDest.Select
'Save a copy
Wb.SaveCopyAs ThisWorkbook.Path & Application.PathSeparator & _
ValidFileName("10.08.18" & " - " & BU7 & " - " & Lvl7 & " - " & Last & ".xlsx")
End If
'Clear the employees
ActiveSheet.Range("A2:AB" & ActiveSheet.Columns.Count + 1).ClearContents
'Remember this manager
Last = Data(sourcerow, 15)
BU7 = Data(sourcerow, 18)
Lvl7 = Data(sourcerow, 25)
'Start the next round
destcol = 0
End If
'Write the employee data into the template
destrow = 0
For sourcecol = 1 To UBound(Data, 2)
If sourcecol = 1 Then
rngDest.Offset(destcol, destrow) = CStr(Format(Data(sourcerow, sourcecol), "000000000"))
Else
rngDest.Offset(destcol, destrow) = Data(sourcerow, sourcecol)
End If
destrow = destrow + 1
Next
'Next column
destcol = destcol + 1
Next
With Wb.Worksheets("Sheet1")
For ActionRow = 2 To 50
If .Cells(ActionRow, 3).Value = "No Action" Then
.Range("A" & ActionRow & ":AB" & ActionRow).Font.Italic = True
.Range("A" & ActionRow & ":AB" & ActionRow).Font.Color = 8421504
End If
Next ActionRow
.Columns("A:ab").Sort key1:=Range("c2"), _
order1:=xlAscending, Header:=xlYes
.Columns("A:A").NumberFormat = "000000000"
End With
End Sub