VBA: рассчитать покрытие в двух листах для каждого соответствующего кода - PullRequest
0 голосов
/ 25 октября 2018

Я пытаюсь вычислить покрытие для определенного совпадающего номера.Я закончил свой код, но потом понял, что я на самом деле сравниваю одни и те же строки на разных листах, а мне нужно сравнить соответствующие строки и столбцы по соответствующему номеру.

, т. Е. Для номера 205090 во входном листе Iнужно сравнивать значения в строках с одинаковым номером на выходе.Проблема заключается в том, что в то время как я делал свой макрос, цифры не в порядке.

В результате получается, сколько недель (неделя за неделей) значение в выходной таблице может покрытьте, что на входе 1.

Вот так должны выглядеть результаты (выходной лист).Меня интересуют только столбцы A (сравниваемое число), D (значение) и E (где результат покрытия - примечание: результаты в этом столбце являются лишь примером).

выходной лист срезультаты

И вот у меня есть лист с данными, которые я сравниваю (входной лист), где меня интересуют столбец A и столбцы G (задержка) до AH (остальное мне нужно покрыть).:

входной лист с данными

Это макрос, который я написал и который, к сожалению, не соответствует соответствующим номерам.

Sub WeeklyCoverage()
'Define lr and r as integers; Double for decimals; String for the text
Dim lr As Long
Dim r As Long
Dim wsr As Worksheet
Dim wsc As Worksheet
Set wsr = Worksheets("SH2_results")
Set wsc = Worksheets("SH3_data")

'Turn screen updating off (to speed up computation)
Application.ScreenUpdating = False

Find the last row with data in column D
lr = wsr.Cells(Rows.Count, "D").End(xlUp).Row

'Loop through all rows in column D starting with row 2 and ending by the value of lr
For r = 2 To lr
'Compare the "COVERAGE" with the "DEALY"
'Not Covered
    If wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value Then
        wsr.Cells(r, "E").Value = "NONE"
'Covered SKLUZ only
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value Then
        wsr.Cells(r, "E").Value = "DELAY"
'Covered till W0
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value Then
        wsr.Cells(r, "E").Value = "W00"
'Covered till W1
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value Then
        wsr.Cells(r, "E").Value = "W01"
'Covered till W2
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value Then
        wsr.Cells(r, "E").Value = "W02"
'Covered till W3
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value Then
        wsr.Cells(r, "E").Value = "W03"
'Covered till W4
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value Then
        wsr.Cells(r, "E").Value = "W04"
'Covered till W5
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value Then
        wsr.Cells(r, "E").Value = "W05"
'Covered till W6
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value Then
        wsr.Cells(r, "E").Value = "W06"
'Covered till W7
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value Then
        wsr.Cells(r, "E").Value = "W07"
'Covered till W8
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value Then
        wsr.Cells(r, "E").Value = "W08"
'Covered till W9
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value Then
        wsr.Cells(r, "E").Value = "W09"
'Covered till W10
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value Then
        wsr.Cells(r, "E").Value = "W10"
'Covered till W11
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value Then
        wsr.Cells(r, "E").Value = "W11"
'Covered till W12
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value Then
        wsr.Cells(r, "E").Value = "W12"
'Covered till W13
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value Then
        wsr.Cells(r, "E").Value = "W13"
'Covered till W14
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value Then
        wsr.Cells(r, "E").Value = "W14"
'Covered till W15
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value Then
        wsr.Cells(r, "E").Value = "W15"
'Covered till W16
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value Then
        wsr.Cells(r, "E").Value = "W16"
'Covered till W17
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value Then
        wsr.Cells(r, "E").Value = "W17"
'Covered till W18
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value Then
        wsr.Cells(r, "E").Value = "W18"
'Covered till W19
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value Then
        wsr.Cells(r, "E").Value = "W19"
'Covered till W20
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value Then
        wsr.Cells(r, "E").Value = "W20"
'Covered till W21
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value Then
        wsr.Cells(r, "E").Value = "W21"
'Covered till W22
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value Then
        wsr.Cells(r, "E").Value = "W22"
'Covered till W23
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value + wsc.Cells(r, "AF").Value Then
        wsr.Cells(r, "E").Value = "W23"
'Covered till W24
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value + wsc.Cells(r, "AF").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value + wsc.Cells(r, "AF").Value + wsc.Cells(r, "AG").Value Then
        wsr.Cells(r, "E").Value = "W24"
'Covered till W25
    ElseIf wsr.Cells(r, "D").Value >= wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value + wsc.Cells(r, "AF").Value + wsc.Cells(r, "AG").Value And _
    wsr.Cells(r, "D").Value < wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value + wsc.Cells(r, "AF").Value + wsc.Cells(r, "AG").Value + wsc.Cells(r, "AH").Value Then
        wsr.Cells(r, "E").Value = "W25"
'Covered till W26
    ElseIf wsr.Cells(r, "D").Value = wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value + wsc.Cells(r, "AF").Value + wsc.Cells(r, "AG").Value + wsc.Cells(r, "AH").Value Then
        wsr.Cells(r, "E").Value = "W26"
'Covered till W27
    ElseIf wsr.Cells(r, "D").Value > wsc.Cells(r, "G").Value + wsc.Cells(r, "H").Value + wsc.Cells(r, "I").Value + wsc.Cells(r, "J").Value + wsc.Cells(r, "K").Value + wsc.Cells(r, "L").Value + wsc.Cells(r, "M").Value + wsc.Cells(r, "N").Value + wsc.Cells(r, "O").Value + wsc.Cells(r, "P").Value + wsc.Cells(r, "Q").Value + wsc.Cells(r, "R").Value + wsc.Cells(r, "S").Value + wsc.Cells(r, "T").Value + wsc.Cells(r, "U").Value + wsc.Cells(r, "V").Value + wsc.Cells(r, "W").Value + wsc.Cells(r, "X").Value + wsc.Cells(r, "Y").Value + wsc.Cells(r, "Z").Value + wsc.Cells(r, "AA").Value + wsc.Cells(r, "AB").Value + wsc.Cells(r, "AC").Value + wsc.Cells(r, "AD").Value + wsc.Cells(r, "AE").Value + wsc.Cells(r, "AF").Value + wsc.Cells(r, "AG").Value + wsc.Cells(r, "AH").Value Then
        wsr.Cells(r, "E").Value = "W26+"

    End If
Next r

'Turn screen updating on
Application.ScreenUpdating = True

End Sub

IsМожно просто настроить мой код, чтобы сделать покрытие с соответствующим номером, или код полностью сломан?

1 Ответ

0 голосов
/ 25 октября 2018

После

For r = 2 To lr

используйте следующий код:

Set FoundCell = wsr.Range("A:A").Find(wsc.Cells(r, "A").Value)
If Not (FoundCell Is Nothing) Then
    FoundRow = FoundCell.Row

'..........................
'.. Use FoundRow as bellow:
'..........................

If wsr.Cells(FoundRow, "D").Value < wsc.Cells(r, "G").Value Then
    wsr.Cells(FoundRow, "E").Value = "NONE"

'........................
'.. your provided code
'........................

End If
...